python-3.x - 在 XGBoost 中应用增量学习进行分类设置时出错(python)

标签 python-3.x classification xgboost

Python 版本:3.5//xgboost 版本:0.7.post3

大家好,

我正在尝试使用 python 中的 xgboost 模块 实现增量学习,其中我的目标变量是二进制的。我想我应该设置参数 "process_type": "update"。问题是我收到一个我无法解决的错误。在这里,我使用 sklearn 的乳腺癌数据集放置了我的代码的示例实现,以便每个人都可以尝试一下。有人知道如何防止发生以下错误吗?

from sklearn import datasets
import xgboost

X_all = datasets.load_breast_cancer().data
y_all = datasets.load_breast_cancer().target

X_first_half = X_all[0:280,:]
X_second_half = X_all[280:,:]
y_first_half = y_all[0:280]
y_second_half = y_all[280:]

model1 = xgboost \
    .train({'objective': 'binary:logistic'},
           dtrain=xgboost.DMatrix(X_first_half, y_first_half),
           xgb_model=None)

model2 = xgboost \
    .train({'objective': 'binary:logistic',
            'process_type': 'update',
            'update': 'refresh',
            'refresh_leaf': True},
           dtrain=xgboost.DMatrix(X_second_half, y_second_half),
           xgb_model=model1)

我得到的错误是:

XGBoostError: b'[15:03:03] src/tree/updater_colmaker.cc:118:
Check failed: tree.param.num_nodes == tree.param.num_roots (19 vs. 1)
ColMaker: can only grow new tree\n\nStack trace returned 1 entries:\n[bt] (0)

最佳答案

这是一个老问题,但如果有人仍然面临同样的问题,请尝试调整 tree_method 参数。

我在增量训练旧模型时收到了相同的错误消息。在我的例子中,旧模型是使用参数 {'tree_method': 'exact'} 训练的,但是我使用的是 {'tree_method': 'hist'} 来更新它。将 tree_method 更改为 exact 后问题得到解决。

或者,如果您能够更新 xgboost,只需更新到 > 1.0 的版本也应该可以解决问题。作为导致此错误的低级 num_roots 参数 was removed在更高版本中。

(还记得将粘贴代码中的 kwarg update 更改为 updater,如评论中提到的@Fortunato。)

关于python-3.x - 在 XGBoost 中应用增量学习进行分类设置时出错(python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49153924/

相关文章:

python - XGBoost python 自定义目标函数

c++ - 将外部库添加到当前的 C++ 项目中

python - 为什么 tempfile 和 os.chdir() 会抛出 RecursionError?

python - 使用列表理解进行元组解包失败,但可以使用 for 循环

python - sklearn : get score of prediction from random forest?

r - SVM奇怪的分类

python-3.x - 如何将按钮重定向到 flask 中的根网址?

python - 为什么 itertools.permutations() 返回一个列表,而不是一个字符串?

python - 使用 adaboost 的 sklearn 中的特征重要性

r - 在 R 中调整 XGboost 参数