I am using this code:
mtry <- round(sqrt(18), 0)
gbmGrid <- expand.grid(
interaction.depth = c(1, 2, 3, 4, 5, 6)
, n.trees = seq(10, 10000, by = 100)
, shrinkage = 0.01
, n.minobsinnode = c(5, 10, 20, 30)
, distribution = 'gaussian'
, method = 'gbm'
, mtry = mtry
)
fitControl <- trainControl(
method = "repeatedcv"
, number = 2
, repeats = 3
)
gbmFit1 <- train(
Y ~
X1
+ X2
, data = Train
, trControl = fitControl
, tuneGrid = gbmGrid
, verbose = FALSE
)
but get:
The tuning parameter grid should have columns mtry
I installed the latest package as some people suggested this and also tried using .mtry. Any ideas? (yes I googled and had a look at SO)
I have taken it back to basics (iris). This works - the non existing mtry for gbm was the issue:
library(datasets)
library(gbm)
library(caret)
grid <- expand.grid(
n.trees = seq(10, 1000, by = 100)
, interaction.depth = c(4)
, shrinkage = c(0.01, 0.1)
, n.minobsinnode = c(5, 10, 20, 30)
)
train_control <- trainControl(
method = "repeatedcv"
, number = 10
, repeats = 10
)
model <- train(Petal.Width ~ Petal.Length
, method = 'gbm'
, distribution = 'gaussian'
, data = iris
, trControl = train_control
, tuneGrid = grid
, verbose = FALSE
)
model
Sorry for wasting your time!
In version >= 6.0-81 of caret
the error message for this type of case is more clear. As an example, considering one supplies an mtry
in the tuning grid when mtry
is not a parameter for the given method.
In caret
< 6.0-81, the following error will occur:
# Error: The tuning parameter grid should have columns mtry
In caret
>= 6.0-81, the following error will occur:
# Error: The tuning parameter grid should not have columns mtry
And here is a reproducible example demonstrating the improved error message.
library(caret)
getNamespaceVersion("caret")
## version
## "6.0-80"
mtry <- round(sqrt(18), 0)
gbmGrid <- expand.grid(
interaction.depth = c(1, 2, 3, 4, 5, 6)
, n.trees = seq(10, 10000, by = 100)
, shrinkage = 0.01
, n.minobsinnode = c(5, 10, 20, 30)
, distribution = 'gaussian'
, method = 'gbm'
, mtry = mtry
)
fitControl <- trainControl(
method = "repeatedcv"
, number = 2
, repeats = 3
)
gbmFit1 <- train(
Species ~ Sepal.Length + Sepal.Width
, data = iris
, trControl = fitControl
, tuneGrid = gbmGrid
, verbose = FALSE
)
# Error: The tuning parameter grid should have columns mtry
library(caret)
getNamespaceVersion("caret")
## version
## "6.0-81"
mtry <- round(sqrt(18), 0)
gbmGrid <- expand.grid(
interaction.depth = c(1, 2, 3, 4, 5, 6)
, n.trees = seq(10, 10000, by = 100)
, shrinkage = 0.01
, n.minobsinnode = c(5, 10, 20, 30)
, distribution = 'gaussian'
, method = 'gbm'
, mtry = mtry
)
fitControl <- trainControl(
method = "repeatedcv"
, number = 2
, repeats = 3
)
gbmFit1 <- train(
Species ~ Sepal.Length + Sepal.Width
, data = iris
, trControl = fitControl
, tuneGrid = gbmGrid
, verbose = FALSE
)
# Error: The tuning parameter grid should not have columns mtry
For more information, refer to the GitHub issue that described and then fixed this behavior: https://github.com/topepo/caret/issues/955
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With