代码之家  ›  专栏  ›  技术社区  ›  Daniel Bestard

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

  •  3
  • Daniel Bestard  · 技术社区  · 6 年前

    Python版本:3.5//xgboost版本:0.7。邮政编码3

    大家好,

    我正在努力实现 增量学习 使用 XG增压模块 在python中 目标变量为二进制 。我想我应该设置参数 “process\u type”:“更新” 。问题是我遇到了一个我无法解决的错误。在这里,我使用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)
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   xdcsy    3 年前

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

    当我增量训练一个旧模型时,我收到了相同的错误消息。在我的例子中,旧模型是用参数训练的 {'tree_method': 'exact'} ,但我使用 {'tree_method': 'hist'} 更新它。更换后问题解决 tree\u方法 exact

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

    (还记得更换kwarg update updater 在粘贴的代码中,如注释中提到的@Fortunato。)

        2
  •  -2
  •   Juan Huguet    6 年前

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

    从文档中:

    process\u type[默认值=默认值]

    要运行的一种增压过程。 选项:{–default–of thelaude,of thelaude–update–of thelaude} –default–创建新树的正常提升过程。 更新:从现有模型开始,仅更新其树。在每个boosting迭代中,从初始模型中获取一棵树,为该树运行指定的更新程序插件序列,并将修改后的树添加到新模型中。新模型将具有相同或更少的树数,这取决于执行的boosting迭代数。目前,以下内置更新程序插件可以有意义地用于此进程类型:刷新、修剪。有了更新,就不能使用创建新树的更新程序插件。