'XGBModel' object 'enable_categorical' - Attribute Error

Viewed 4816

I built a XGBClassifier model using Xgboost 1.4.2 version and saved in S3 in pickle format.

from xgboost import XGBClassifier

xgb_model = XGBClassifier()

xgb_model.fit(x_Traintfidf, y_Train)

xgb_predictions = xgb_model.predict(x_Testtfidf) 

xgb_predictions = [round(value) for value in xgb_predictions]

from sklearn.metrics import accuracy_score
accuracy = accuracy_score(y_Test.to_list(), xgb_predictions) 
print("Accuracy: %.2f%%" % (accuracy * 100.0))

# Save model to s3 as pickle file.

Next, I read back in the pickled model from s3 and when I try to do predictions, it throws the error:

AttributeError: 'XGBModel' object has no attribute 'enable_categorical'

I have a tf-idf transformed matrix, I am passing in to get predictions.

Any idea why I get the error above that when I unpickle the model and do predictions?

2 Answers

You might want to double check the xgboost version in your virtual env using pip list | grep xgboost to make sure its actually 1.4.2.

As mentioned by @bill-the-lizard, enable_categorical is new in version 1.5.0 of XGBoost, so you will correctly receive the error mentioned in your question at version 1.4.x

Related