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?


1 Answer 1


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.

  • $\begingroup$ Is there something going on with 1se, or is that a different package? $\endgroup$
    – Dave
    Commented Sep 14, 2021 at 13:33
  • $\begingroup$ 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: stats.stackexchange.com/questions/138569/… $\endgroup$
    – frelk
    Commented Sep 14, 2021 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.