TypeError when reading xgboost model from disk with joblib.load

Viewed 666

I am simply trying to read XGBoost model via joblib (os.path.exists(self._classifier_xgboost_path) returns True as expected):

self._xgboost_model = joblib.load(self._classifier_xgboost_path)

However, i get the following error:

  File "/home/iai/Desktop/barak_8/main.py", line 150, in <module>
    main()
  File "/home/iai/Desktop/barak_8/main.py", line 32, in main
    classifier = Classifier(config=config)
  File "/home/iai/Desktop/barak_8/classifiers.py", line 56, in __init__
    if os.path.exists(self._classifier_xgboost_path) \
  File "/home/iai/Desktop/barak_8/venv/lib/python3.6/site-packages/joblib/numpy_pickle.py", line 585, in load
    obj = _unpickle(fobj, filename, mmap_mode)
  File "/home/iai/Desktop/barak_8/venv/lib/python3.6/site-packages/joblib/numpy_pickle.py", line 504, in _unpickle
    obj = unpickler.load()
  File "/usr/lib/python3.6/pickle.py", line 1050, in load
    dispatch[key[0]](self)
  File "/usr/lib/python3.6/pickle.py", line 1323, in load_newobj
    obj = cls.__new__(cls, *args)
TypeError: NoneType.__new__(X): X is not a type object (NoneType)

Versions:

Python 3.6
xgboost 1.3.1
joblib 1.0.0
2 Answers

This most probably caused by missing some dependent import for the xgboost model. I faced this issue earlier today and it was caused by missing import in the environment, in my case. I was missing scikit-learn in my environment.

Actually I recently faced the same problem, and I thought it may be useful for others to mention the solution that worked for me.

So briefly, the problem was that the scikit-learn version in the code that performed the joblib.dump was higher than the one use in the code that should perform the joblib.load

Indeed : joblib.dump was made with scikit-learn = 0.24.1 joblib.load in another repository which has scikit-learn = 0.18.2

so all what you need to do is to work with the same version of scikit-learn (or clause version for example me I simply upgraded 0.18.2 to 0.21.3 and it works as well)

Related