XGBoost CV 和最佳迭代

XGBoost CV and best iteration

我正在使用 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],因此为了获得最佳轮数,我们减去提前停止轮数.

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

是的,如果您 best_nrounds = int(best_nrounds / 0.8) 认为您的验证集占整个训练数据的 20%(另一种说法是您执行了 5 折交叉验证),这听起来是正确的。

规则可以概括为:

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

或者,如果您不执行 CV,而是执行一次验证:

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

您可以看到应用此规则的示例here on Kaggle(查看评论)。

您可以通过 'res.best_iteration'

获得最佳迭代次数