首页 > 解决方案 > xgb.plot.multi.trees 括号里的数字是什么意思?

问题描述

这不是树的数量,因为我只训练了 25 棵树。它也不是变量的值。括号中值的比例很明显,这是没有意义的,因为记录了许多变量。我检查了文档,没有任何解释。有什么想法或其他参考吗?

df1 <- xgb.train(data = X_train_dmat, 
               eta = 0.1,
               max_depth = 5, 
               nround=25, 
               subsample = 0.5,
               colsample_bytree = 0.5,
               booster = 'gbtree',
               objective = 'reg:squarederror',
               nthread = 3
)

xgb.plot.multi.trees(model = df1, 
                     features_keep = 5, 
                     use.names=FALSE,
                     plot_width = NULL,
                     plot_height = NULL,
                     render = TRUE
                     )

标签: rdecision-treexgboost

解决方案


查看源代码https://github.com/dmlc/xgboost/blob/master/R-package/R/xgb.plot.multi.trees.R#L94,这是在树中创建节点的部分:

  nodes.dt <- tree.matrix[
        , .(Quality = sum(Quality))
        , by = .(abs.node.position, Feature)
      ][, .(Text = paste0(Feature[1:min(length(Feature), features_keep)],
                          " (",
                          format(Quality[1:min(length(Quality), features_keep)], digits=5),
                          ")") %>%
                   paste0(collapse = "\n"))
        , by = abs.node.position]

具体来说,这是编写这些数字的代码:

format(Quality[1:min(length(Quality), features_keep)], digits=5)

因此,这些数字显示了每个节点的质量,我认为这反映了该节点划分数据的适当程度。自从我处理这些模型以来已经有一段时间了,而且我从来没有精明过,所以我不能确定我的解释。如果您想进一步解释质量的含义,您可以深入挖掘源代码以弄清楚它是如何计算的。


推荐阅读