based on code presented in thread: How to find a GBM Prediction Interval
I am trying to apply this to my dataset. Below is my full code, and I am having issues with the bootstrap function.
library(caret)
require(foreign)
set.seed(825)
Ridership <- read.spss("V:/Metro/Coverage/ROUTE_MODEL2.sav",use.value.labels=TRUE, to.data.frame = TRUE)
set.seed(825)
fitControl <- trainControl(method = "cv", number = 2)
gbmGrid <- expand.grid(interaction.depth = (20:21), n.trees = (750), shrinkage = c(0.07))
x <- Ridership[, -148]
y <- Ridership[, 148]
gbmFit <- train(x=x,y=y,"gbm", tuneGrid = gbmGrid, n.minobsinnode = 2, trControl =fitControl, verbose=FALSE)
gbmFit
x.pt <- quantile(Ridership$TOT_RIDERSHIP, c(0.25, 0.5, 0.75))
p <- plot(gbmFit, newdata = Ridership[, -148], grid.levels = x.pt, return.grid = TRUE)
p
library(boot)
bootfun <- function(data, indices) {
data <- data[indices,]
x <- Ridership[, -148]
y <- Ridership[, 148]
gbmFit <- train(x=x,y=y,"gbm", tuneGrid = gbmGrid, n.minobsinnode = 2, trControl =fitControl, verbose=FALSE)
plot(gbmFit, newdata = Ridership[, -148], grid.levels = x.pt, return.grid = TRUE)$y
}
b <- boot(data = Ridership, statistic = bootfun, R = 5)
lims <- t(apply(b$t, 2, FUN = function(x) quantile(x, c(0.025, 0.975))))
When I run the code, the lim(only show 1, and nothing more. I am not exactly sure what to define in the Bootstrap function. I have flipped through the bootstrap package code, but it still is not clear to me what I am doing wrong. Thanks in advance!
gbmFit
withgbmFit$finalModel
in your call toplot.gbm
? $\endgroup$