xgboost cover是怎么计算的?

How is xgboost cover calculated?

谁能解释一下 xgboost R 包中的 Cover 列是如何在 xgb.model.dt.tree 函数中计算的?

文档中说 Cover "is a metric to measure the number of observations affected by the split".

当你运行下面的代码时,xgboost文档中给出了这个函数,树0的节点0的Cover是1628.2500。

data(agaricus.train, package='xgboost')

#Both dataset are list with two items, a sparse matrix and labels
#(labels = outcome column which will be learned).
#Each column of the sparse Matrix is a feature in one hot encoding format.
train <- agaricus.train

bst <- xgboost(data = train$data, label = train$label, max.depth = 2,
               eta = 1, nthread = 2, nround = 2,objective = "binary:logistic")

#agaricus.test$data@Dimnames[[2]] represents the column names of the sparse matrix.
xgb.model.dt.tree(agaricus.train$data@Dimnames[[2]], model = bst)

火车数据集中有 6513 个观察值,所以谁能解释为什么树 0 的节点 0 的 Cover 是这个数字 (1628.25) 的四分之一?

此外,树 1 的节点 1 的 Cover 是 788.852 - 这个数字是如何计算的?

如有任何帮助,我们将不胜感激。谢谢。

封面在xgboost中定义为:

the sum of second order gradient of training data classified to the leaf, if it is square loss, this simply corresponds to the number of instances in that branch. Deeper in the tree a node is, lower this metric will be

https://github.com/dmlc/xgboost/blob/f5659e17d5200bd7471a2e735177a81cb8d3012b/R-package/man/xgb.plot.tree.Rd 没有特别详细的记录....

为了计算覆盖率,我们需要知道 树中该点的预测,以及关于损失函数的二阶导数

幸运的是,您的示例中 0-0 节点中每个数据点(其中 6513 个)的预测为 .5。这是一个全局默认设置,您在 t=0 时的第一个预测是 .5。

base_score [ default=0.5 ] the initial prediction score of all instances, global bias

http://xgboost.readthedocs.org/en/latest/parameter.html

二元逻辑(即您的 objective 函数)的梯度为 p-y,其中 p = 您的预测,y = 真实标签。

因此,hessian(我们为此需要)是 p*(1-p)。 注意:Hessian 可以在没有 y,真实标签的情况下确定。

所以(把它带回家):

6513 * (.5) * (1 - .5) = 1628.25

在第二棵树中,那个点的预测不再都是.5,sp让我们得到一棵树之后的预测

p = predict(bst,newdata = train$data, ntree=1)

head(p)
[1] 0.8471184 0.1544077 0.1544077 0.8471184 0.1255700 0.1544077

sum(p*(1-p))  # sum of the hessians in that node,(root node has all data)
[1] 788.8521

注意,对于线性(平方误差)回归,hessian 始终为一个,因此封面指示该叶中有多少个示例。

最大的收获是 cover 是由 objective 函数的 hessian 定义的。关于获得梯度和二元逻辑函数的 hessian 的大量信息。

这些幻灯片有助于了解他为什么使用粗麻布作为权重,还可以解释 xgboost 如何与标准树分开。 https://homes.cs.washington.edu/~tqchen/pdf/BoostedTree.pdf