我正在使用插入符号来拟合 gbm 模型。当我打电话时trainedGBM$finalModel$fit
,我得到的输出看起来正确。
但是当我打电话时predict(trainedGBM$finalModel, origData, type="response")
,我得到了非常不同的结果,predict(trainedGBM$finalModel, type="response")
即使附加了 origData 也会产生不同的结果。在我看来,这些调用应该产生相同的输出。有人可以帮我确定问题吗?
library(caret)
library(gbm)
attach(origData)
gbmGrid <- expand.grid(.n.trees = c(2000),
.interaction.depth = c(14:20),
.shrinkage = c(0.005))
trainedGBM <- train(y ~ ., method = "gbm", distribution = "gaussian",
data = origData, tuneGrid = gbmGrid,
trControl = trainControl(method = "repeatedcv", number = 10,
repeats = 3, verboseIter = FALSE,
returnResamp = "all"))
ntrees <- gbm.perf(trainedGBM$finalModel, method="OOB")
data.frame(y,
finalModelFit = trainedGBM$finalModel$fit,
predictDataSpec = predict(trainedGBM$finalModel, origData, type="response", n.trees=ntrees),
predictNoDataSpec = predict(trainedGBM$finalModel, type="response", n.trees=ntrees))
上面的代码产生以下部分结果:
y finalModelFit predictDataSpec predictNoDataSpec
9000 6138.8920 2387.182 2645.993
5000 3850.8817 2767.990 2467.157
3000 3533.1183 2753.551 2044.578
2500 1362.9802 2672.484 1972.361
1500 5080.2112 2449.185 2000.568
750 2284.8188 2728.829 2063.829
1500 2672.0146 2359.566 2344.451
5000 3340.5828 2435.137 2093.939
0 1303.9898 2377.770 2041.871
500 879.9798 2691.886 2034.307
3000 2928.4573 2327.627 1908.876