将树的集成可视化为一个单一的整体单元。
用法
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 版本中,此函数的一些参数已被弃用或重命名。如果传递已弃用或重命名的参数,将(默认)抛出警告并改用其当前等效项。如果使用 '严格模式'选项,此警告将变为错误。 - 如果传递了既不是当前函数参数也不是已弃用或重命名参数的附加参数,则根据“严格模式”选项,将抛出警告或错误。 - 重要: - ...将在未来版本中删除,所有当前的弃用警告将变为错误。请仅使用构成函数签名的参数。
详细信息
请注意,此函数不适用于对分类数据进行拟合的模型。
此函数通过将树的集成压缩到单个树图表示中,试图以连贯的方式捕获梯度提升树模型的复杂性。目标是提高通常被视为黑盒的模型的解释性。
注意:此函数仅适用于基于树的助推器模型。
它利用了二叉树的形状仅由其深度定义这一事实(因此,在提升模型中,所有树都具有相似的形状)。
此外,树倾向于重用相同的特征。
该函数将每棵树投射到一棵树上,并为每个位置保留 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)
}