“XGBModel”对象“enable_categorical”-属性错误

use*_*057 6 python pickle xgboost

我使用 Xgboost 1.4.2 版本构建了 XGBClassifier 模型,并以 pickle 格式保存在 S3 中。

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.
Run Code Online (Sandbox Code Playgroud)

接下来,我读回 s3 中的 pickled 模型,当我尝试进行预测时,它会抛出错误:

AttributeError:“XGBModel”对象没有属性“enable_categorical”

我有一个tf-idf变换后的矩阵,我正在传递以获得预测。

知道为什么当我取消模型并进行预测时会出现上述错误吗?

小智 1

您可能需要仔细检查虚拟环境中的 xgboost 版本,pip list | grep xgboost以确保其实际上是 1.4.2。