I have the following code to tune the mtry hyperparameter of a random forest regression model:
set.seed(42)
mtry <- 1:10
# Define train control
trControl <- trainControl(method = "cv",
number = 10,
search = "grid")
for (i in mtry) {
rf_random <- train(Price.Gas~., data=data_train,
method = "rf",
mtry = i,
metric = "RMSE",
trControl = trControl)
}
However, I get the error (that actually repeats itself for different values of mtry):
model fit failed for Fold01: mtry= 2 Error in randomForest.default(x, y, mtry = param$mtry, ...) :
formal argument "mtry" matched by multiple actual arguments
How can I make this work to test different mtry values?