FunctionTransformer Pickling Error
See original GitHub issueDescription
When pickling a FunctionTransformer
transformer instance, the wrapped function does not get pickled:
AttributeError: Can’t get attribute ‘f’ on <module ‘main’ …>
Steps/Code to Reproduce
from sklearn.preprocessing import FunctionTransformer
import pickle
def f(x): return x*x
pickled = pickle.dumps(FunctionTransformer(f))
del f
unpickled = pickle.loads(pickled) # Causes the exception
Versions
Windows-7-6.1.7601-SP1 Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] NumPy 1.14.4 SciPy 1.1.0 Scikit-Learn 0.19.1
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top Results From Across the Web
pickling error for a sklearn pipeline with custom transformations
I am trying to pickle a Pipeline with some custom transformation over my features and store it in Google cloud storage but i...
Read more >Module Main has No Attribute... (on Pipelines and Pickles)
In this post I'll present a common problem that occurs when serializing and restoring scikit-learn pipelines, as well as a solution that I've ......
Read more >The implications of pickling ML models - - Uwe's Blog
When you have trained a machine learning model (pipeline), you will make predictions directly afterwards to assess its quality.
Read more >sklearn.preprocessing.FunctionTransformer
Constructs a transformer from an arbitrary callable. A FunctionTransformer forwards its X (and optionally y) arguments to a user-defined function or function ...
Read more >FunctionTransformer in Sklearn2PMML - Google Groups
problem is that this callable must be "persistable" when the FunctionTransformer is dumped into a Pickle file; this condition is
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It does persists with
joblib
See:
Was this issue resolved? I am having the same issue. scikit-learn version: 0.20.2 and 0.21.2 both.