我希望使用该GBM软件包进行逻辑回归,但它的回答略微超出0-1范围.我已经尝试了0-1预测(bernoulli和adaboost)的建议分布参数,但这实际上比使用更糟糕gaussian.
GBM_NTREES = 150
GBM_SHRINKAGE = 0.1
GBM_DEPTH = 4
GBM_MINOBS = 50
> GBM_model <- gbm.fit(
+ x = trainDescr
+ ,y = trainClass
+ ,distribution = "gaussian"
+ ,n.trees = GBM_NTREES
+ ,shrinkage = GBM_SHRINKAGE
+ ,interaction.depth = GBM_DEPTH
+ ,n.minobsinnode = GBM_MINOBS
+ ,verbose = TRUE)
Iter TrainDeviance ValidDeviance StepSize Improve
1 0.0603 nan 0.1000 0.0019
2 0.0588 nan 0.1000 0.0016
3 0.0575 nan 0.1000 0.0013
4 0.0563 nan 0.1000 0.0011
5 0.0553 nan 0.1000 0.0010
6 0.0546 nan 0.1000 0.0008
7 0.0539 nan 0.1000 0.0007
8 0.0533 nan 0.1000 0.0006
9 0.0528 nan 0.1000 0.0005
10 0.0524 nan 0.1000 0.0004
100 0.0484 nan 0.1000 0.0000
150 0.0481 nan 0.1000 -0.0000
> prediction <- predict.gbm(object = GBM_model
+ ,newdata = testDescr
+ ,GBM_NTREES)
> hist(prediction)
> range(prediction)
[1] -0.02945224 1.00706700
Run Code Online (Sandbox Code Playgroud)
伯努利:
GBM_model <- gbm.fit(
x = trainDescr
,y = trainClass
,distribution = "bernoulli"
,n.trees = GBM_NTREES
,shrinkage = GBM_SHRINKAGE
,interaction.depth = GBM_DEPTH
,n.minobsinnode = GBM_MINOBS
,verbose = TRUE)
prediction <- predict.gbm(object = GBM_model
+ ,newdata = testDescr
+ ,GBM_NTREES)
> hist(prediction)
> range(prediction)
[1] -4.699324 3.043440
Run Code Online (Sandbox Code Playgroud)
并且adaboost:
GBM_model <- gbm.fit(
x = trainDescr
,y = trainClass
,distribution = "adaboost"
,n.trees = GBM_NTREES
,shrinkage = GBM_SHRINKAGE
,interaction.depth = GBM_DEPTH
,n.minobsinnode = GBM_MINOBS
,verbose = TRUE)
> prediction <- predict.gbm(object = GBM_model
+ ,newdata = testDescr
+ ,GBM_NTREES)
> hist(prediction)
> range(prediction)
[1] -3.0374228 0.9323279
Run Code Online (Sandbox Code Playgroud)
我做错了什么,我是否需要对数据进行预处理(缩放,居中),或者我是否需要进入并手动设置/覆盖值,例如:
prediction <- ifelse(prediction < 0, 0, prediction)
prediction <- ifelse(prediction > 1, 1, prediction)
Run Code Online (Sandbox Code Playgroud)
Hon*_*Ooi 15
来自?predict.gbm:
返回预测向量.默认情况下,预测的范围为f(x).例如,对于伯努利损失,返回值在对数优势标度上,对数标度上的泊松损失,以及在对数危险等级上的coxph.
如果type ="response",则gbm将转换回与结果相同的比例.目前唯一的影响是返回bernoulli的概率和泊松的预期计数.对于其他发行版"响应"和"链接"返回相同.
因此,如果您使用distribution="bernoulli",则需要转换预测值以将它们重新缩放为[0,1] : p <- plogis(predict.gbm(model)). 使用distribution="gaussian"实际上是回归而不是分类,虽然我很惊讶预测不在[0,1]中:我的理解是gbm仍然基于树,所以预测的值不应该去超出训练数据中的值.