Skip to content

Instantly share code, notes, and snippets.

@lewtun
Last active January 21, 2020 08:28
Show Gist options
  • Save lewtun/d9744974d60fd4a35d94f46de64f9c2e to your computer and use it in GitHub Desktop.
Save lewtun/d9744974d60fd4a35d94f46de64f9c2e to your computer and use it in GitHub Desktop.
class TemplateTransformer(BaseEstimator, TransformerMixin):
""" An example transformer that returns the element-wise square root."""
def __init__(self, demo_param='demo'):
self.demo_param = demo_param
def fit(self, X, y=None):
"""A reference implementation of a fitting function for a transformer."""
X = check_array(X, accept_sparse=True)
self.n_features_ = X.shape[1]
# Return the transformer
return self
def transform(self, X):
""" A reference implementation of a transform function."""
# Check is fit had been called
check_is_fitted(self, 'n_features_')
# Input validation
X = check_array(X, accept_sparse=True)
# Return transformed input
return np.sqrt(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment