【发布时间】: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