gpt4 book ai didi

r - xgboost 覆盖率是如何计算的?

转载 作者:行者123 更新时间:2023-12-04 00:34:52 25 4
gpt4 key购买 nike

谁能解释一下Cover xgboost中的栏目R包在xgb.model.dt.tree中计算功能?

在文档中,它说 Cover “是衡量受拆分影响的观察数量的指标”。

当您运行以下代码时,在 xgboost 中给出此函数的文档,Cover树 0 的节点 0 是 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 个观测值,所以谁能解释为什么 Cover树 0 的节点 0 是这个数字的四分之一 (1628.25)?

另外, Cover对于树 1 的节点 1 是 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 个)的预测值为 0.5。这是一个全局默认设置,您在 t=0 时的第一个预测是 0.5。

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



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

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

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

所以(带回家):

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

在第二棵树中,该点的预测不再都是 0.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 始终为 1,因此封面指示该叶子中有多少个示例。

最大的收获是cover是由目标函数的hessian定义的。在获得梯度和二元逻辑函数的粗麻布方面有很多信息。

这些幻灯片有助于了解他为什么使用粗麻布作为权重,并解释了 xgboost split 与标准树不同。 https://homes.cs.washington.edu/~tqchen/pdf/BoostedTree.pdf

关于r - xgboost 覆盖率是如何计算的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33520460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com