I'm trying to use caret to find the best parameters for a gbm model. This code is identical to what I've used on other data sets and can't figure out the error.
It seems to run the model but can't create predictions.
predictions failed for Fold2: interaction.depth=4, shrinkage=0.005, n.trees=200 Error in apply(tmp, 2, function(x, nm = modelFit$obsLevels) ifelse(x >= :
dim(X) must have a positive length
Here's the full code:
library(caret)
library(gbm)
myControl <- trainControl(method='cv', number=2, summaryFunction=twoClassSummary,
classProbs=TRUE, savePredictions=TRUE, verboseIter=TRUE)
df1 <- data.frame(Y = round(runif(1000), 0), x1=runif(1000), x2=runif(1000) )
X <- df1[,c('x1','x2')]
Y <- factor(paste('X', df1[,'Y']))
gbm_model <- train(X, Y, method='gbm', metric='ROC', trControl=myControl
,distribution='bernoulli', tuneGrid=expand.grid(.n.trees=seq(100, 200, by=100)
,.interaction.depth=seq(2, 4, by=2), .shrinkage=c(.005)))
Any suggestions?
EDIT: I'm using gbm 2.1
and caret 5.16.24