Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jaradc/d72851f81ebae521db5790bbb8245fb9 to your computer and use it in GitHub Desktop.
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
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