我怎样才能在 Xgboost 中解决这个警告?

新手上路,请多包涵

我有一个包含 53987 行、32 列和 8 个类的不平衡数据集。我正在尝试执行多类分类。这是我的代码和相应的输出:

 from sklearn.metrics import classification_report, accuracy_score
import xgboost
xgb_model = xgboost.XGBClassifier(num_class=7, learning_rate=0.1, num_iterations=1000, max_depth=10, feature_fraction=0.7,
                              scale_pos_weight=1.5, boosting='gbdt', metric='multiclass')
hr_pred = xgb_model.fit(x_train, y_train).predict(x_test)
print(classification_report(y_test, hr_pred))

[10:03:13] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.3.0/src/learner.cc:541:
Parameters: { boosting, feature_fraction, metric, num_iterations, scale_pos_weight } might not be used.

This may not be accurate due to some parameters are only used in language bindings but
passed down to XGBoost core.  Or some parameters are not used but slip through this verification. Please open an issue if you find above cases.

[10:03:13] WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.3.0/src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'multi:softprob' was changed from 'merror' to 'mlogloss'. Explicitly set eval_metric if you'd like to restore the old behavior.
          precision    recall  f1-score   support

     1.0       0.84      0.92      0.88      8783
     2.0       0.78      0.80      0.79      4588
     3.0       0.73      0.59      0.65      2109
     4.0       1.00      0.33      0.50         3
     5.0       0.42      0.06      0.11       205
     6.0       0.60      0.12      0.20       197
     7.0       0.79      0.44      0.57       143
     8.0       0.74      0.30      0.42       169

accuracy                           0.81     16197
macro avg       0.74      0.45      0.52     16197
weighted avg       0.80      0.81      0.80     16197

max_depth_list = [3,5,7,9,10,15,20,25,30]

for max_depth in max_depth_list:
    xgb_model = xgboost.XGBClassifier(max_depth=max_depth, seed=777)
    xgb_pred = xgb_model.fit(x_train, y_train).predict(x_test)
    xgb_f1_score_micro = f1_score(y_test, xgb_pred, average='micro')

    xgb_df = pd.DataFrame({'tree depth':max_depth_list,
                            'accuracy':xgb_f1_score_micro})
    xgb_df

WARNING: C:/Users/Administrator/workspace/xgboost-win64_release_1.3.0/src/learner.cc:1061: Starting in XGBoost 1.3.0, the default evaluation metric used with the objective 'multi:softprob' was changed from 'merror' to 'mlogloss'. Explicitly set eval_metric if you'd like to restore the old behavior.

我该如何修复这些警告?

原文由 mineral 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.3k
2 个回答

如果您不想更改任何行为,只需将 eval_metric='mlogloss' 设置如下。

 xgb_model = xgboost.XGBClassifier(num_class=7,
                                  learning_rate=0.1,
                                  num_iterations=1000,
                                  max_depth=10,
                                  feature_fraction=0.7,
                                  scale_pos_weight=1.5,
                                  boosting='gbdt',
                                  metric='multiclass',
                                  eval_metric='mlogloss')

从警告日志中,您将知道要设置什么 eval_metric 算法来消除警告。主要是 mloglosslogloss

原文由 Wei Chen 发布,翻译遵循 CC BY-SA 4.0 许可协议

我遇到了完全相同的问题,原因是我对 XGBClassifier 使用了不正确的超参数。在你的情况下,尝试删除这些超参数 boosting, feature_fraction, metric, num_iterations, scale_pos_weight 因为它们不再有效,你可以看看 文档

这是您的错误消息:

这可能不准确,因为某些参数仅用于语言绑定但传递给 XGBoost 核心。 或者有些参数没有用到,却漏过了这个验证。

原文由 Hamzah 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题