python-3.x - 在 XGBoost 中应用增量学习进行分类设置时出错(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)

最佳答案

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

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

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

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

https://stackoverflow.com/questions/49153924/

相关文章:

java - 如何在 GraphQL Java 上拆分模式

spring - @Transactional(read-only = true) 的目的是什么

sql - Oracle left join 表现得像 inner join

git - 如何在 VS Code 中只提交跟踪的文件?

macos - 有没有办法防止 OSX 用数千个 .DS_Store 文件污染我的项目?

json - 如何在 vuejs 中将 JSON 对象发布到 Web 服务器?

google-forms - 在谷歌表单中将文本右对齐

javascript - 如何从提供 NET::ERR_CERT_AUTHORITY_INVALID

python - 在 spark-submit 之前安装 pyspark 作业的要求

google-chrome-extension - 将 Google Chrome 扩展程序限制为选