Xgboost: bst.best_iteration 和 bst.best_ntree_limit 有什么区别?

当我使用 xgboost 为 2-cates classification problem 训练我的数据时,我想使用提前停止来获得最佳模型,但我对在我的预测中使用哪一个感到困惑,因为提前停止将返回 3 个不同的选择。
例如,我应该使用

preds = model.predict(xgtest, ntree_limit=bst.best_iteration)

或者我应该使用
preds = model.predict(xgtest, ntree_limit=bst.best_ntree_limit)

还是两者都对,它们应该适用于不同的情况?如果是这样,我如何判断使用哪一个?

这是xgboost文档的原始引用,但它没有给出原因,我也没有找到这些参数之间的比较:

 

Early Stopping

If you have a validation set, you can use early stopping to find the optimal number of boosting rounds. Early stopping requires at least one set in evals. If there's more than one, it will use the last.

train(..., evals=evals, early_stopping_rounds=10)

The model will train until the validation score stops improving. Validation error needs to decrease at least every early_stopping_rounds to continue training.

If early stopping occurs, the model will have three additional fields: bst.best_score, bst.best_iteration and bst.best_ntree_limit. Note that train() will return a model from the last iteration, not the best one. Pr ediction

A model that has been trained or loaded can perform predictions on data sets.

# 7 entities, each contains 10 features 
data = np.random.rand(7, 10) 
dtest = xgb.DMatrix(data) 
ypred = bst.predict(dtest)

If early stopping is enabled during training, you can get predictions from the best iteration with bst.best_ntree_limit:

ypred = bst.predict(dtest,ntree_limit=bst.best_ntree_limit)



提前致谢。

最佳答案

在我看来,这两个参数指的是相同的想法,或者至少有相同的目标。但我宁愿使用:

preds = model.predict(xgtest, ntree_limit=bst.best_iteration)
从源码我们可以看到here那个best_ntree_limit将被放弃以支持 best_iteration .
def _get_booster_layer_trees(model: "Booster") -> Tuple[int, int]:
    """Get number of trees added to booster per-iteration.  This function will be removed
    once `best_ntree_limit` is dropped in favor of `best_iteration`.  Returns
    `num_parallel_tree` and `num_groups`.
    """
此外,best_ntree_limit已从 EarlyStopping 中删除文档页面。
所以我认为这个属性只存在于向后兼容的原因。因此,根据此代码片段和文档,我们可以假设 best_ntree_limit正在或将被弃用。

关于python - Xgboost:bst.best_score、bst.best_iteration 和 bst.best_ntree_limit 有什么区别?,我们在Stack Overflow上找到一个类似的问题: python - Xgboost: what is the difference among bst.best_score, bst.best_iteration and bst.best_ntree_limit? - Stack Overflow

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值