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 Regression, specifying scale = TRUE in the prepare() function. This will help us apply the centering and scaling values from your training data to the test/validation ...
Ridge regression
Get Mastering Machine Learning with R - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.