我无法弄清楚如何从经过训练的带有损失函数的二元结果中解释Prediction在pretty.gbm.tree单个树上调用的结果。我正在使用v2.1.1。gbmbernoulligbm
例子
data('ptitanic', package='rpart.plot') # note this is not the default data(Titanic)
ptitanic$died <- 2-as.integer(ptitanic$survived) #survived is fctr w/ 2 levels died/survived
mean(ptitanic$died) # 0.618 death rate
form <- as.formula('died ~ sex + age + pclass + sibsp + parch')
library('gbm')
set.seed(1)
m <- gbm(form,
distribution = 'bernoulli',
data = ptitanic,
interaction.depth=4,
n.trees=50)
summary(m)
mean(predict(m, ptitanic, type='response',n.trees=50)) # 0.618 death rate
# let's look at the 1st tree
t <- pretty.gbm.tree(m, i=1)
# I want to see the split variable names instead of indices
# The indices are -1 for terminal, 0 for first term, 1 for second term, etc.
t$SplitVar <- c('Terminal',attr(terms(form),'term.labels'))[t$SplitVar+2]
# The predictions at nodes look like:
head(t$Prediction)
# [1] -2.066845e-05 -1.472631e-03 -2.374948e-03 -4.808952e-04 -1.472631e-03 7.829118e-04
我试过的:
根据?predict.gbm,该函数将返回一个对数赔率向量
返回预测向量。默认情况下,预测在 f(x) 的范围内。例如,对于伯努利损失,返回值是对数赔率标度,...
因此,Prediction树中的似乎应该是对数赔率,我应该能够通过以下方式获得概率估计:
IE:
t$OR <- exp(t$Prediction)
t$Prob <- 1/(1/t$OR + 1)
head(t$Prob)
#[1] 0.5000094 0.4996384 0.4994387 0.4998654 0.4996384 0.5002175
非常奇怪的是,根节点的优势比约为 1,或 p = 0.5——尽管上面提到的总体死亡率为 61.8%。所以也许它是想告诉我相对风险?
有一个有点神秘的细节?predict.gbm:
gbm 的预测不包括偏移项。如果需要,用户可以将偏移值添加到预测值。
在查看第一棵树时,我需要添加偏移量吗?(我可能理解需要在后续的树中做加法效果,但第一个?)如果是这样,我该怎么做?