Created
August 2, 2018 16:32
-
-
Save jaradc/d72851f81ebae521db5790bbb8245fb9 to your computer and use it in GitHub Desktop.
A pipeline example showing how to use kwargs in a function, and how to use FunctionTransformer from sklearn to decode URLs
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 fit_model(X, y, **kwargs): | |
print(kwargs) | |
print(kwargs['max_iter']) | |
pipeline = Pipeline([ | |
('decode', FunctionTransformer(func=lambda x: x.apply( | |
lambda url: parse.unquote(parse.unquote(url))), validate=False)), | |
('cvect', CountVectorizer(binary=True, max_features=1000, stop_words='english', | |
token_pattern=r'\b\w[\w\.\-\,]+\b')), | |
('clf', MLPClassifier(verbose=1, solver='sgd', max_iter=kwargs['max_iter'] or 1000, | |
tol=0.00001, learning_rate='adaptive', learning_rate_init=0.05)), | |
]) | |
pipeline.fit(X, y) | |
return pipeline |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment