Reintroducing glmnet

Machine Learning with caret in R

Zach Mayer

Data Scientist at DataRobot and co-author of caret

glmnet review

  • Linear model with built-in variable selection
  • Great baseline model
  • Advantages
    • Fits quickly
    • Ignores noisy variables
    • Provides interpretable coefficients
Machine Learning with caret in R

Example: glmnet on churn data

set.seed(42)
model_glmnet <- train(
  churn ~ ., 
  churnTrain,
  metric = "ROC",
  method = "glmnet",
  tuneGrid = expand.grid(
    alpha = 0:1, 
    lambda = 0:10 / 10
  ),
  trControl = myControl
)
Machine Learning with caret in R

Visualize results

plot(model_glmnet)

The image shows a line plot of ROC curve versus regularization parameter for two mixing percentage values of 0 and 1. ROC is much higher when the mixing percentage is 1.

Machine Learning with caret in R

Plot the coefficients

plot(model_glmnet$finalModel)

Athe image shows a custom glmnet plot of coefficients versus L1 norm

Machine Learning with caret in R

Let’s practice!

Machine Learning with caret in R

Preparing Video For Download...