0

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?

Matt Frank
  • 135
  • 3

1 Answers1

3

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.

frelk
  • 1,117
  • 1
  • 8
  • 19
  • Is there something going on with `1se`, or is that a different package? – Dave Sep 14 '21 at 13:33
  • The 1se choice of lambda can be calculated in the same package. It is a heuristic that uses a slightly different criterion to choose the "best" lambda, see: https://stats.stackexchange.com/questions/138569/why-is-lambda-within-one-standard-error-from-the-minimum-is-a-recommended-valu – frelk Sep 14 '21 at 13:48