Custom tuning grids

Machine Learning with caret in R

Zach Mayer

Data Scientist at DataRobot and co-author of caret

Pros and cons of custom tuning

  • Pass custom tuning grids to tuneGrid argument
  • Advantages
    • Most flexible method for fitting caret models
    • Complete control over how the model is fit
  • Disadvantages
    • Requires some knowledge of the model
    • Can dramatically increase run time
Machine Learning with caret in R

Custom tuning example

# Define a custom tuning grid
myGrid <- data.frame(mtry = c(2, 3, 4, 5, 10, 20))
# Fit a model with a custom tuning grid
set.seed(42)
model <- train(
  Class ~ ., 
  data = Sonar, 
  method = "ranger",            
  tuneGrid = myGrid
)
# Plot the results
plot(model)
Machine Learning with caret in R

Custom tuning

The image shows a line plot of accuracy versus randomly selected predictors, with a peak at x equal to 10.

Machine Learning with caret in R

Let's practice!

Machine Learning with caret in R

Preparing Video For Download...