XGBoost CV和最佳迭代

2024-04-28 11:36:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用XGBoost cv为我的模型找到最佳的轮次数。如果有人能确认(或反驳),我将不胜感激,最佳回合数是:

    estop = 40
    res = xgb.cv(params, dvisibletrain, num_boost_round=1000000000, nfold=5, early_stopping_rounds=estop, seed=SEED, stratified=True)

    best_nrounds = res.shape[0] - estop
    best_nrounds = int(best_nrounds / 0.8)

即:完成的总轮数是res.shape[0],因此为了得到最优的轮数,我们减去提前停止的轮数。

然后,我们根据用于验证的分数,放大轮数。对吗?


Tags: 模型resparams次数numcvbestshape
2条回答

是的,当你做best_nrounds = int(best_nrounds / 0.8)的时候,如果你认为你的验证集是你整个训练数据的20%(另一种说法是你做了5倍的交叉验证),这听起来是正确的。

然后,可以将规则概括为:

n_folds = 5
best_nrounds = int((res.shape[0] - estop) / (1 - 1 / n_folds))

或者,如果您不执行简历,只执行一次验证:

validation_slice = 0.2
best_nrounds = int((res.shape[0] - estop) / (1 - validation_slice))

您可以看到应用此规则的示例here on Kaggle(请参阅注释)。

您可以通过“res.best_iteration”获得最佳迭代次数

相关问题 更多 >