python - Xgboost n_estimators 与显示的树数不匹配

标签 python parameters xgboost

也许我错过了一些东西,我不明白,我需要你的帮助。

我正在使用这些线训练 xgb 模型

 XGB = xgb.XGBClassifier(objective ='multi:softprob',
                        learning_rate = 0.3,
                        max_depth = 1, 
                        n_estimators = 3,
                        n_jobs = 5)
clf = XGB.fit(X_train, Y_train) 

当我打印 XGB 模型时,它说我确实训练了 3 棵树:

XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1,
              colsample_bynode=1, colsample_bytree=1, gamma=0,
              learning_rate=0.3, max_delta_step=0, max_depth=1,
              min_child_weight=1, missing=None, n_estimators=3, n_jobs=5,
              nthread=None, objective='multi:softprob', random_state=0,
              reg_alpha=0, reg_lambda=1, scale_pos_weight=1, seed=None,
              silent=None, subsample=1, verbosity=1)  

但是当我运行这一行来查看功能被分割的位置

dump_list = clf.get_booster().get_dump()

我得到 9 行

['0:[f0<0.942677855] yes=1,no=2,missing=1\n\t1:leaf=-0.103566267\n\t2:leaf=0.43779847\n',
 '0:[f0<0.954393268] yes=1,no=2,missing=1\n\t1:leaf=0.200365365\n\t2:leaf=-0.216199294\n',
 '0:[f13<0.651464462] yes=1,no=2,missing=1\n\t1:leaf=0.276390254\n\t2:leaf=-0.219127133\n',
 '0:[f0<0.917573214] yes=1,no=2,missing=1\n\t1:leaf=-0.110939182\n\t2:leaf=0.292450339\n',
 '0:[f0<0.966108799] yes=1,no=2,missing=1\n\t1:leaf=0.135595635\n\t2:leaf=-0.194633663\n',
 '0:[f11<0.6690377] yes=1,no=2,missing=1\n\t1:leaf=0.202725366\n\t2:leaf=-0.196870551\n',
 '0:[f0<0.899163187] yes=1,no=2,missing=1\n\t1:leaf=-0.107093893\n\t2:leaf=0.230380043\n',
 '0:[f0<0.974476993] yes=1,no=2,missing=1\n\t1:leaf=0.10007298\n\t2:leaf=-0.180789232\n',
 '0:[f13<0.588702917] yes=1,no=2,missing=1\n\t1:leaf=0.235898077\n\t2:leaf=-0.177840069\n']

这是否意味着安装了 9 棵树?

我注意到我在这里得到的行数与数据集中的类数相关。这里我使用包含 3 个类的数据集。当我使用包含 2 个类的数据集时,我得到 6 行。这暗示了类的数量和拟合树的数量之间的关系,这实际上没有意义。所以我的另一个问题是 clf.get_booster().get_dump() 的输出的解释是什么。

谢谢。

最佳答案

Ivan Libedinsky 回答了我的部分问题。评论中以下问题的答案是:xgboost 中的树以一种与其他方式相对的方式生长,这就是为什么算法的每次迭代看起来都有 3 棵树,因为我的数据库中有 3 个类。

关于python - Xgboost n_estimators 与显示的树数不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58879755/

相关文章:

python - sphinxcontrib-autoprogram在获取解析器后是否解析参数?

python - 重置主 GUI 窗口

python - 文件打开 : Is this bad Python style?

c++ - C++中的模板模板参数。使用实例

delphi - 实际 var 参数和形式 var 参数的类型必须相同

R-XGBoost : Error building DMatrix

python - 如何在 Mac 操作系统的 Rodeo GUI 中安装 xgboost?

python - 两个数组之间的加权平均元素

c - 这个C函数声明是什么意思?

Scala - 'this' 在 Scala 中对于事件对象可以为 null 吗?