Last active
November 22, 2015 12:33
-
-
Save zacstewart/c2230357d336d20957b9 to your computer and use it in GitHub Desktop.
Example transformer for tapping into your Pipeline
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
def TapTransformer(TransformerMixin): | |
def __init__(self, fn): | |
self.fn = fn | |
def transform(self, X, **transform_params): | |
self.fn(x) | |
return X | |
def fit(self, X, y=none, **fit_params): | |
return self | |
features = [] | |
def save_features(f) | |
features.append(f) | |
pipeline = Pipeline([ | |
('extract_essays', EssayExractor()), | |
('features', FeatureUnion([ | |
('ngram_tf_idf', Pipeline([ | |
('counts', CountVectorizer()), | |
('tf_idf', TfidfTransformer()) | |
])), | |
('essay_length', LengthTransformer()), | |
('misspellings', MispellingCountTransformer()) | |
])), | |
('print_features', TapTransformer(lambda X: print(X))), | |
('save_features', TapTransformer(save_features)) | |
('classifier', MultinomialNB()) | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you provide examples of your LengthTransformer and MispellingCountTransformer?