Search code examples
rregressionsvmr-caret

Error : The tuning parameter grid should have columns mtry, SVM Regression


I'm trying to tune an SVM regression model using the caret package. Below the code:

control <- trainControl(method="cv", number=5)
tunegrid <- expand.grid(.mtry=c(6:12), .ntree=c(500, 600, 700, 800, 900, 1000))
set.seed(2)
custom <- train(CRTOT_03~., data=train, method="rf", metric="rmse", tuneGrid=tunegrid, trControl=control)
summary(custom)
plot(custom)

and Im getting the error

Error : The tuning parameter grid should have columns mtry

Solution

  • You are using Random Forests, not Support Vector machines. You are getting an error, because you can set .mtry only in the tuning grid for Random Forests in caret The ntree parameter is set by passing ntree to train, e.g.

    control <- trainControl(method="cv", number=5)
    tunegrid <- expand.grid(.mtry = 6:12)
    set.seed(2)
    custom <- train(CRTOT_03~., 
              data=train, method="rf", 
              metric="rmse", 
              tuneGrid=tunegrid, 
              ntree = 1000,
              trControl=control)
    

    ntree is passed directly to randomForest