Last active
January 1, 2016 01:39
-
-
Save jnothman/8074321 to your computer and use it in GitHub Desktop.
Stacking in scikit-learn, a quick attempt
This file contains hidden or 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
from sklearn.base import BaseEstimator, TransformerMixin | |
class Transformer(BaseEstimator, TransformerMixin): | |
def __init__(self, fn): | |
self.fn = fn | |
def fit(self, X, y): | |
return self | |
def transform(self, X): | |
return self.fn(X) | |
if __name__ == '__main__': | |
from sklearn import datasets, svm, pipeline, cross_validation | |
iris = datasets.load_iris() | |
p = pipeline.Pipeline([ | |
('t', Transformer(svm.LinearSVC().fit(iris.data, iris.target).decision_function)), | |
('c', svm.LinearSVC()), | |
]) | |
print(cross_validation.cross_val_score(p, iris.data, iris.target)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this going to introduce bias since the transformer was fitted on the entire dataset?