Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'XGBModel' object 'enable_categorical' - Attribute Error

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?

like image 634
user9431057 Avatar asked Aug 16 '26 02:08

user9431057


1 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.

like image 79
Tushar Avatar answered Aug 17 '26 16:08

Tushar