I am using sklearn's Pipeline and FunctionTransformer with a custom function
from sklearn.externals import joblib
from sklearn.preprocessing import FunctionTransformer
from sklearn.pipeline import Pipeline
This is my code:
def f(x):
return x*2
pipe = Pipeline([("times_2", FunctionTransformer(f))])
joblib.dump(pipe, "pipe.joblib")
del pipe
del f
pipe = joblib.load("pipe.joblib") # Causes an exception
And I get this error:
AttributeError: module '__ main__' has no attribute 'f'
How can this be resolved ?
from Saving an sklearn pipeline with its dependencies
No comments:
Post a Comment