将树的集合可视化为一个单独的集体单位。
用法
xgb.plot.multi.trees(
model,
features_keep = 5,
plot_width = NULL,
plot_height = NULL,
render = TRUE,
...
)
参数
- model
xgb.Booster
类的对象。如果它包含特征名称(可以通过setinfo()
设置),这些名称将用于此函数的输出。- features_keep
在多树的每个位置保留的特征数量,默认为 5。
- plot_width, plot_height
图形的宽度和高度(像素)。这些值被传递给
DiagrammeR::render_graph()
。- render
是否渲染图形?默认为
TRUE
。- ...
未使用。
此函数在之前 XGBoost 版本中的一些参数已弃用或已重命名。如果传递了弃用或重命名的参数,将(默认情况下)抛出警告并改用其当前等效项。如果在 '严格模式'选项 下使用,此警告将变为错误。
如果传递了既不是当前函数参数也不是弃用或重命名参数的额外参数,则根据“严格模式”选项抛出警告或错误。
重要提示:
...
将在未来的版本中移除,并且所有当前的弃用警告将变为错误。请仅使用构成函数签名的参数。
详情
请注意,此函数不适用于针对分类数据拟合的模型。
此函数试图通过将树集合压缩为单个树图表示来以连贯的方式捕获梯度提升树模型的复杂性。目标是提高通常被视为黑箱的模型的解释性。
注意:此函数仅适用于基于树增强器 (tree booster) 的模型。
它利用了二叉树的形状仅由其深度定义的事实(因此,在提升模型中,所有树都具有相似的形状)。
此外,树倾向于重用相同的特征。
该函数将每棵树投影到一棵树上,并为每个位置保留基于“特征增益 (Gain per feature)”测量的 features_keep
个最靠前的特征。
此函数的灵感来自这篇博客文章:https://wellecks.wordpress.com/2015/02/21/peering-into-the-black-box-visualizing-lambdamart/
示例
data(agaricus.train, package = "xgboost")
## Keep the number of threads to 2 for examples
nthread <- 2
data.table::setDTthreads(nthread)
model <- xgboost(
agaricus.train$data, factor(agaricus.train$label),
nrounds = 30,
verbosity = 0L,
nthreads = nthread,
max_depth = 15,
learning_rate = 1,
min_child_weight = 50
)
p <- xgb.plot.multi.trees(model, features_keep = 3)
print(p)
# Below is an example of how to save this plot to a file.
if (require("DiagrammeR") && require("DiagrammeRsvg") && require("rsvg")) {
fname <- file.path(tempdir(), "tree.pdf")
gr <- xgb.plot.multi.trees(model, features_keep = 3, render = FALSE)
export_graph(gr, fname, width = 1500, height = 600)
}