Skip to content

Instantly share code, notes, and snippets.

@baatout

baatout/pickle_export.py

Last active Sep 8, 2018
Embed
What would you like to do?
Pickle export
# with X_train, X_test, Y_train, Y_test
import dill
from sklearn_pandas import DataFrameMapper
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import FunctionTransformer
def is_adult(x): return x > 18
clf = Pipeline([
("mapper", DataFrameMapper([
(['age'], FunctionTransformer(is_adult)),
(features, None)
])),
("classifier", LogisticRegression())
])
clf.fit(X_train, Y_train)
print(clf.score(X_test, Y_test))
with open('pipeline.pk', 'wb') as f:
dill.dump(clf, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment