Skip to content

Instantly share code, notes, and snippets.

Forked from larsmans/
Last active August 31, 2015 13:46
What would you like to do?
k-means feature mapper for scikit-learn
from sklearn.base import BaseEstimator, TransformerMixin
from sklearn.metrics.pairwise import rbf_kernel
class KMeansTransformer(BaseEstimator, TransformerMixin):
def __init__(self, centroids):
self.centroids = centroids
def fit(self, X, y=None):
return self
def transform(self, X, y=None):
return rbf_kernel(X, self.centroids)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment