Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
binary operators on all estimators
from sklearn.base import BaseEstimator
def piper(self, other):
from sklearn.pipeline import make_pipeline, Pipeline
if isinstance(self, Pipeline):
steps = ([estimator for (name, estimator) in self.steps] + [other])
return make_pipeline(*steps)
else:
return make_pipeline(self, other)
def unionizer(self, other):
from sklearn.pipeline import make_union, FeatureUnion
if isinstance(self, FeatureUnion):
steps = ([estimator for (name, estimator) in self.steps] + [other])
return make_union(*steps)
else:
return make_union(self, other)
BaseEstimator.__rshift__ = piper
BaseEstimator.__mul__ = unionizer
@amueller

This comment has been minimized.

Copy link
Owner Author

commented Jul 28, 2016

On second though, should have called it "make @GaelVaroquaux cry"

@jnothman

This comment has been minimized.

Copy link

commented Jul 31, 2016

Oh, no! You forgot to add that parameter renaming magic I once wrote so that all double-underscored parameter settings are eradicated forever and replaced with custom incantations. Without parameter renaming magic, est is far from substitutable with est >> est2.

@amueller

This comment has been minimized.

Copy link
Owner Author

commented Sep 12, 2016

@jnothman sorry just saw this. But I'm not following

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.