Check sklearn version before loading model with joblib

I followed this guide to save a machine learning model for future reference. The model was dropped in one car:

from sklearn.externals import joblib
joblib.dump(clf, 'model.pkl')

And when I downloaded it joblib.load('model.pkl')on another machine, I received this warning:

UserWarning: an attempt to disband the DecisionTreeClassifier score from version up to 0.18 when using version 0.18.1. This may result in code violation or incorrect results. Use at your own risk.

So, is there a way to find out the sklearn version of a saved model in order to compare it with the current version?

+4
source share
2 answers

​​ scikit-learn 0.18. 0.18, scikit-learn,

estimator.__getstate__()['_sklearn_version']

, , __setstate__ , . , . ,

import warnings

with warnings.catch_warnings():
      warnings.simplefilter("ignore", category=UserWarning)
      estimator = joblib.load('model.pkl')

0.18 , , , , not hasattr(estimator, '__getstate') , , pre-0.18.

+3

, model.pkl joblib.dump. . !

0

Source: https://habr.com/ru/post/1663763/


All Articles