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

相关推荐

  1. equals==什么区别

    2024-01-06 10:00:03       15 阅读
  2. session cookie 什么区别

    2024-01-06 10:00:03       36 阅读
  3. vuejQuery什么区别

    2024-01-06 10:00:03       37 阅读
  4. ThinkPHPPHP什么区别

    2024-01-06 10:00:03       40 阅读
  5. https http 什么区别

    2024-01-06 10:00:03       45 阅读
  6. RedisMemcached什么区别

    2024-01-06 10:00:03       35 阅读
  7. Redis memcache 什么区别

    2024-01-06 10:00:03       39 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-06 10:00:03       17 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-06 10:00:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-06 10:00:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-06 10:00:03       18 阅读

热门阅读

  1. JVM面试系列-03

    2024-01-06 10:00:03       27 阅读
  2. 牧马人K87调节键盘灯光模式

    2024-01-06 10:00:03       38 阅读
  3. Es 学习记录

    2024-01-06 10:00:03       33 阅读
  4. Shell:常用命令之dirname与basename

    2024-01-06 10:00:03       30 阅读
  5. 动手学深度学习—深度学习计算

    2024-01-06 10:00:03       29 阅读
  6. Apache绑定指定地址与端口

    2024-01-06 10:00:03       36 阅读
  7. ARM CCA机密计算架构软件栈简介

    2024-01-06 10:00:03       36 阅读
  8. leetcode231 判断一个给定的整数是否是2的n次幂

    2024-01-06 10:00:03       33 阅读
  9. Winform、WPF如何解决前端卡死问题

    2024-01-06 10:00:03       32 阅读
  10. Hbase进阶

    2024-01-06 10:00:03       31 阅读