Ibotta / pure-predict

Machine learning prediction in pure Python
Apache License 2.0
86 stars 7 forks source link

Sklearn object having a preprocessor function cannot be converted #15

Open ogunoz opened 3 years ago

ogunoz commented 3 years ago

pure_sklearn.map.convert_estimator function crashes during a conversion of a sklearn unit having a functional variable (a CountVectorizer with a preprocessor parameter in my case).

ValueError: Object contains invalid type: <class 'function'>

To Reproduce

from pure_sklearn.map import convert_estimator
from sklearn.feature_extraction.text import CountVectorizer

vectorizer = CountVectorizer(preprocessor=lambda x:x)
vectorizer.fit(["aaaa", "bbbb", "cccc"])

convert_estimator(vectorizer)

Additional context The bug can be fixed by adding built-in types.FunctionType into TYPES tuple of pure_sklearn.utils.py module. So I suggest to replace:

TYPES = (int, float, str, bool, type)

with:

from types import FunctionType

TYPES = (int, float, str, bool, type, FunctionType)
denver1117 commented 3 years ago

Hi thanks for raising the issue. Would you be open to submitting a PR with the suggested changes including a unit test to ensure that this error doesn't persist? I'd gladly approve the PR if it is indeed a basic update as you suggest.