Luisa Roa
Luisa Roa

Reputation: 123

joblib.load and pickle.load error "No attribute 'XGBoostLabelEncoder'"

I'm trying to load a XBGClassifier model with joblib and pickle.

When using joblib loaded_model = joblib.load('trained_model.sav') I'm getting the following error: AttributeError: module 'xgboost.compat' has no attribute 'XGBoostLabelEncoder'

And with pickle loaded_model = pickle.load(open('trained_model.sav', 'rb')) I get AttributeError: Can't get attribute 'XGBoostLabelEncoder' on <module 'xgboost.compat' from 'C:\Users\Usuario\Anaconda3\lib\site-packages\xgboost\compat.py'>

I installed xgboost again but it doesn't work, what might be the issue?

Upvotes: 5

Views: 4508

Answers (2)

Connor
Connor

Reputation: 19

I encountered this error when debugging my scoring script for a batch endpoint, for an Azure AutoML generated model. I verified that the version used to train the model & in my environment were the same.
Version: XGBoost 1.5.2

I went into my local copy of compat.py and amended two lines of code: from sklearn.preprocessing import LabelEncoder to from sklearn.preprocessing import LabelEncoder as XGBoostLabelEncoder and LabelEncoder = object to XGBoostLabelEncoder= object.

This then enabled my scoring script to run and model to output scores.

Upvotes: 0

quents
quents

Reputation: 121

Make sure that the xgboost versions in the saved and loaded environments are the same. You need to change the version of xgboost in the environment that you try to load model.

Upvotes: 1

Related Questions