Skip to content

Instantly share code, notes, and snippets.

@georgepar
Last active October 15, 2018 15:13
Show Gist options
  • Save georgepar/b53c01466d6649c8583497d120b9b479 to your computer and use it in GitHub Desktop.
Save georgepar/b53c01466d6649c8583497d120b9b479 to your computer and use it in GitHub Desktop.
from sklearn.base import BaseEstimator, ClassifierMixin
class EuclideanClassifier(BaseEstimator, ClassifierMixin):
"""Classify samples based on the distance from the mean feature value"""
def __init__(self):
self.X_mean_ = None
def fit(self, X, y):
"""
This should fit classifier. All the "work" should be done here.
Calculates self.X_mean_ based on the mean
feature values in X for each class.
self.X_mean_ becomes a numpy.ndarray of shape
(n_classes, n_features)
fit always returns self.
"""
raise NotImplementedError
#return self
def predict(self, X):
"""
Make predictions for X based on the
euclidean distance from self.X_mean_
"""
raise NotImplementedError
def score(self, X, y):
"""
Return accuracy score on the predictions
for X based on ground truth y
"""
raise NotImplementedError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment