【发布时间】:2021-10-01 15:26:53
【问题描述】:
下面的代码生成了一个简单的 xgboost 模型,以显示我所看到的问题。建立模型后,我们使用该模型进行预测,并在我们的数据中获取第二行。如果我们对第 10 和第 9 个模型的预测之间的相对差异进行对数,它应该给我们对第 10 棵树的预测:在这种情况下为 0.00873184。
现在,如果我们使用树的输入(矩阵“a”,第 2 行的值为 0.1234561702)并运行模型,我们预计预测值为 0.0121501638。但是,看起来在第二次拆分 (
有人知道发生了什么吗?
版本:
R:4.1.0
xgboost:1.4.1.1
dplyr:1.0.7
数据表:1.14.0
library(xgboost)
library(dplyr)
library(data.table)
set.seed(2)
a <- matrix(runif(1000,0.1234561,0.1234562),
ncol=1,nrow=1000)
colnames(a) <- c("b")
d <- abs(rnorm(1000,3*a[,1]))
d2 <- xgb.DMatrix(data = a,label = d)
e <- xgboost::xgboost(data=d2,nrounds=10,method="hist",objective="reg:gamma")
xgb.plot.tree(e$feature_names,e,trees=9)
x <- 2
log((predict(e,a,ntreelimit = 10)/predict(e,a,ntreelimit = 9)))[x]
format(a[x,],nsmall=10)
【问题讨论】:
标签: r tree prediction xgboost