在 XGBoost 中为分类设置应用增量学习时出错 (python)

Error when applying incremental learning in XGBoost for a classification setting (python)

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)

我认为他正在尝试实现一种批量训练,我的意思是在不向集成中添加更多树的情况下使用新数据点进一步训练模型。换句话说,将当前 trees/leafs 更新为新的数据点。

来自文档:

process_type, [default=’default’]

A type of boosting process to run. Choices: {‘default’, ‘update’} ‘default’: the normal boosting process which creates new trees. ‘update’: starts from an existing model and only updates its trees. In each boosting iteration, a tree from the initial model is taken, a specified sequence of updater plugins is run for that tree, and a modified tree is added to the new model. The new model would have either the same or smaller number of trees, depending on the number of boosting iteratons performed. Currently, the following built-in updater plugins could be meaningfully used with this process type: ‘refresh’, ‘prune’. With ‘update’, one cannot use updater plugins that create new trees.

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

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

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

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