Ridge Regression – How GLMNet in R Determines the Penalty in Ridge Regression

glmnetrregularizationridge regression

in R, once I call https://www.rdocumentation.org/packages/glmnet/versions/4.1-2/topics/cv.glmnet with alpha = 0, I will magically get a set of coefficients from ridge regression, without having to specify anything about the penalty coefficient.

How does glmnet determine the penalty for ridge regression?

Best Answer

The cv.glmnet function uses k-fold cross-validation to estimate an optimal penalty term. The default for this software is to use 10 folds. So, the software fits many ridge regressions on a grid of different penalty values and then chooses the value of the penalty parameter that minimizes estimated out-of-sample prediction error, using cross-validation to estimate the out-of-sample prediction error for each choice of the parameter value.