【问题标题】:XGBoost reporting eval-auc has been declining,but train-auc has been rising,whether the result is normal?XGBoost上报eval-auc一直在下降,但是train-auc一直在上升,结果是否正常?
【发布时间】:2017-07-26 08:50:21
【问题描述】:

我想用 XGBoost 的early_stopping_rounds 做非过拟合训练。为此,我使用以下代码:

parameters = {'nthread': 4,'objective': 'binary:logistic','learning_rate': 0.06,'max_depth': 6,'min_child_weight': 3,
        'silent': 0,'gamma': 0,'subsample': 0.7,'colsample_bytree': 0.5,'n_estimators': 5,
        'missing': -999,'scale_pos_weight': scale_pos_weight,'seed': 4789,'eval_metric':'auc','early_stopping_rounds': 100}
X_train, X_test, y_train, y_test =train_test_split(train_feature,train_label, test_size=0.3, random_state=4789)
dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)
evallist = [(dtest, 'eval'), (dtrain, 'train')]
bst = xgb.train(parameters, dtrain,num_boost_round=1500, evals=evallist)

当打印中间结果时,我得到如下日志:

[1469]  eval-auc:0.912417   train-auc:0.986104
[16:04:23] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 110 extra nodes, 0 pruned nodes, max_depth=6
[1470]  eval-auc:0.912412   train-auc:0.986118
[16:04:27] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 102 extra nodes, 0 pruned nodes, max_depth=6
[1471]  eval-auc:0.912405   train-auc:0.986129
[16:04:30] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 116 extra nodes, 0 pruned nodes, max_depth=6
[1472]  eval-auc:0.912383   train-auc:0.986143
[16:04:34] src/tree/updater_prune.cc:74: tree pruning end, 1 roots, 116 extra nodes, 0 pruned nodes, max_depth=6
[1473]  eval-auc:0.912375   train-auc:0.986159

现在我想知道这个训练结果是否正确?如何检测我的模型是否过度拟合以及选择多少轮?

【问题讨论】:

  • 是的,这是正确的,如果您的训练 AUC 正在增加,但验证 AUC 正在减少 - 这是过度拟合的迹象。关于 early_stopping_rounds 的一般建议 - 您的 num_boost_round = 150 的 10% 适合您的情况。这是一篇关于它的文章 - machinelearningmastery.com/…
  • 谢谢,当运行[220] 时,我观察到我的验证 AUC 开始下降,而 train-auc 仍然增加。我很困惑我在参数dict中设置了early_stopping_rounds,但是它并没有停止,为什么?从这个结果中,我应该设置num_boost_round = 220?

标签: python machine-learning xgboost training-data


【解决方案1】:

正如@Stepan Novikov 所说,您看到的结果是正确的——您的模型刚刚开始过度拟合。

关于您的第二个问题,early_stopping_rounds 参数的工作方式是在 N 轮结束后停止训练,而 eval-aug 没有任何改进(N 是 early_stopping_rounds)。请注意,eval-auc 值可能会在两者之间降低,但只要在最后 N 轮中有任何绝对改善,训练就会继续。

在您的示例中,轮 [1469] 具有 eval-auc 的最大值,因此训练将在轮 [1569] 之前停止(根据配置,100 轮之后)。

最后,达到的最佳轮数应存储在示例的bst 变量中。

【讨论】:

  • 非常感谢您的回答,我明白了~
猜你喜欢
  • 2018-01-31
  • 2017-05-24
  • 2018-09-09
  • 2018-05-14
  • 2022-11-11
  • 1970-01-01
  • 2015-09-18
  • 2019-06-01
  • 2017-02-23
相关资源
最近更新 更多