Isaiah
Isaiah

Reputation: 63

gbm not recognising tuning parameter grid

The script:

library(caret)
library(gbm)

formula <- price ~ carat + depth + table + x + y + z

mtryGrid <- expand.grid(interaction.depth = seq(1, 7, by = 2),
                    n.trees = seq(100, 1000, by = 50),
                    n.minobsinnode = 10,
                    verbose = FALSE,
                    shrinkage = c(0.01, 0.1))

set.seed(100)
gbm_model <- train(formula, 
               data = diamonds,
               method = "gbm",
               tuneGrid = mtryGrid,
               trControl = trainControl(method = "cv"))

gives the error:

Error: The tuning parameter grid should have columns n.trees, interaction.depth, shrinkage, n.minobsinnode

although mtryGrid seems to have all four required columns

I'm using R3.5.1, caret 6.0-80, gbm 2.1.3

Upvotes: 1

Views: 1948

Answers (1)

PKumar
PKumar

Reputation: 11128

So you should not put verbose=FALSE in the expand.grid. The error clearly suggests that it can only take n.trees, interaction.depth etc in the expand.grid. Removing verbose=FALSE has given me a result for the equation.

I hope this helps

So the below works on my system. To suppress the printing use verbose=FALSE in the train function.

formula <- price ~ carat + depth + table + x + y + z

mtryGrid <- expand.grid(interaction.depth = seq(1, 7, by = 2),
                        n.trees = seq(100, 1000, by = 50),
                        n.minobsinnode = 10,
                        shrinkage = c(0.01, 0.1))


expand.grid(n.trees=c(10,20,60),shrinkage=c(0.05,0.1,0.5),n.minobsinnode = c(3,5),interaction.depth=c(3,5))

set.seed(100)
gbm_model <- train(formula, 
               data = diamonds,
               method = "gbm",
               tuneGrid = mtryGrid,
               trControl = trainControl(method = "cv"), verbose=FALSE)

Upvotes: 1

Related Questions