也许我缺少了一些东西,我想不通,需要您的帮助。
我正在使用这些行训练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()的输出的解释是什么。
谢谢。
最佳答案
该格式对于'get_dumps()`有点混乱,我相信(尽管不是100%肯定)您的树可以看成是:
tree_1 = ['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',]
tree_2= ['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',]
tree_3 = ['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']]
抱歉,我在手机上格式化,将尝试尽快修复它。