首页 > 解决方案 > Xgboost n_estimators 与显示的树数不匹配

问题描述

也许我错过了什么,我想不通,我需要你的帮助。

我正在使用这些行训练 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() 的输出的解释是什么。

谢谢你。

标签: pythonparametersxgboost

解决方案


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


推荐阅读