当我使用 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)
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