Explore a wider model space

Machine Learning with caret in R

Zach Mayer

Data Scientist at DataRobot and co-author of caret

Random forests require tuning

  • Hyperparameters control how the model is fit
  • Selected "by hand" before the model is fit
  • Most important is mtry
    • Number of randomly selected variables used at each split
  • Lower value = more random
  • Higher value = less random
  • Hard to know the best value in advance
Machine Learning with caret in R

Example: sonar data

  • tuneLength argument to caret::train()
  • Tells caret how many different variations to try
# Load some data
library(caret)
library(mlbench)
data(Sonar)
# Fit a model with a deeper tuning grid
model <- train(
  Class ~ ., 
  data = Sonar, 
  method = "ranger", 
  tuneLength = 10
)
# Plot the results
plot(model)
Machine Learning with caret in R

Plot the results

The image contains a line plot of bootstrap accuracy versus the number of randomly selected parameters. It rises to a peak around x = 14, then drops off quickly.

Machine Learning with caret in R

Let's practice!

Machine Learning with caret in R

Preparing Video For Download...