Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading XGBoost Model: ModuleNotFoundError: No module named 'sklearn.preprocessing._label'

Tags:

pickle

xgboost

I'm having issues loading a pretrained xgboost model using the following code:

xgb_model = pickle.load(open('churnfinalunscaled.pickle.dat', 'rb'))

And when I do that, I get the following error:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-29-31e7f426e19e> in <module>()
----> 1 xgb_model = pickle.load(open('churnfinalunscaled.pickle.dat', 'rb'))

ModuleNotFoundError: No module named 'sklearn.preprocessing._label'

I haven't seen anything online so any help would be much appreciated.

like image 415
madsthaks Avatar asked Dec 26 '19 20:12

madsthaks


People also ask

How to fix ‘no module named ‘XGBoost’ error in Python?

The ModuleNotFoundError: No module named ‘xgboost’ error occurs when we try to import the ‘ xgboost ‘ module without installing the package or if you have not installed it in the correct environment. We can resolve the issue by installing the xgboost module by running the pip install xgboost command.

What is modulenotfounderror in Python?

In Python, ModuleNotFoundError: No module named ‘xgboost’ error occurs if we try to import the ‘ xgboost ‘ module without installing the package or if you have not installed it in the correct environment.

How to install XGBoost and scikit-learn?

Presumably, you'll have to run the command: conda install -c conda-forge xgboost pip install -U scikit-learn To install your machine learning packages. Share Improve this answer

How to use XGBoost in Python?

xgboost is not a built-in module (it doesn’t come with the default python installation) in Python; you need to install it explicitly using the pip installer and then use it. XGBoost is an optimized distributed gradient boosting library designed to be highly efficient , flexible, and portable.


1 Answers

I was able to solve my issue. Simply update scikit-learn from 0.21.3 to 0.22.0 seems to solve the issue. Along the way I have to update my pandas version to 0.25.2 as well.

The cue is provided in this link: https://www.gitmemory.com/vruusmann, where it states:

During Scikit-Learn version upgrade from 0.21.X to 0.22.X many modules were renamed (typically, by prepending an underscore character to the module name). For example, sklearn.preprocessing.label.LabelEncoder became sklearn.preprocessing._label.LabelEncoder.

like image 109
ccy Avatar answered Sep 19 '22 16:09

ccy