【发布时间】:2019-08-12 21:28:40
【问题描述】:
我有一个关于我应该从XGBoost 中选择哪个决策树的问题。
我将以下面的代码为例。
#import packages
import xgboost as xgb
import matplotlib.pyplot as plt
# create DMatrix
df_dmatrix = xgb.DMatrix(data = X, label = y)
# set up parameter dictionary
params = {"objective":"reg:linear", "max_depth":2}
#train the model
xg_reg = xgb.train(params = params, dtrain = df_dmatrix, num_boost_round = 10)
#plot the tree
xgb.plot_tree(xg_reg, num_trees = n) # my question related to here
我在 xg_reg 模型中创建了 10 棵树,我可以通过在我的最后一个代码中将 n 设置为等于树的索引来绘制其中的任何一棵。
我的问题是:我如何知道哪棵树最能解释数据集?总是最后一个吗?还是我应该确定要在树中包含哪些特征,然后选择包含这些特征的树?
【问题讨论】:
标签: python decision-tree xgboost