For our purposes here, we want to focus on finding the optimal mix of lambda and our elastic net mixing parameter, alpha. This is done using the following simple three-step process:
- Use the expand.grid() function in base R to create a vector of all of the possible combinations of alpha and lambda that we want to investigate.
- Use the trainControl() function from the caret package to determine the resampling method; we'll use 5-fold cross-validation again.
- Train a model to select our alpha and lambda parameters using glmnet() in caret's train() function.
Once we've selected our parameters, we'll apply them to the test data in the same way as we did with ridge regression and LASSO.