Last active
January 21, 2020 08:28
-
-
Save lewtun/d9744974d60fd4a35d94f46de64f9c2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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