Artur Pschybysz
Artur Pschybysz

Reputation: 303

How to find the sklearn version of pickled model?

I have a pickled sklearn model, which I need to get to run. This model, however, is trained in unknown version of sklearn.

When I look up the model in debugger, I find that there is a bunch of strange tracebacks inside, instead of the keys you'd expect, for example:

decision_function -> 'RandomForestClassifier' object has no attribute 'decision_function'
fit_predict -> 'RandomForestClassifier' object has no attribute 'fit_predict'
score_samples -> 'RandomForestClassifier' object has no attribute 'score_samples'

How can I get this model to run? Does these error message hint you anything?

EDIT: The solution is to brute force search the sklearn version. In my case when I got to the correct major version, the error message pointed me to the correct minor version.

Upvotes: 2

Views: 1151

Answers (2)

Artur Pschybysz
Artur Pschybysz

Reputation: 303

Just like @rickhg12hs suggested, the python -m pickletools your_pickled_model_file does the job!

The output is quite long, so I recommend using head: python -m pickletools your_pickled_model_file | head -100

Upvotes: 1

Santiago Isaza
Santiago Isaza

Reputation: 1

You can know the version of a pickled model after scikit-learn 0.18. Using

model.__getstate__()['_sklearn_version']

So at least you will know if it is pre 0.18 or newer.

Upvotes: 0

Related Questions