Ridge regression

The package we're using will be glmnet. I like it because it has a built-in cross-validation function, standardizes the input features, and returns coefficients on their original scale, so it's quite easy to implement. If you standardize your features yourself, you can specify standardize = FALSE in the function. Either way, don't run features that aren't standardized as the results will be undesirable as the regularization won't be applied evenly. If you do standardize on your own, I recommend utilizing the vtreat package functions as we did in Chapter 2, Linear Regressionspecifying scale = TRUE in the prepare() function. This will help us apply the centering and scaling values from your training data to the test/validation ...

Get Mastering Machine Learning with R - Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.