I'm doing some research and want to get the best lambda with cross validation in python. For my dataset the R! package glmnet works pretty well, but I can not find out how it's implemented. There are so many parameters and even in the source code I can't find any lines where they perform CV. Does anyone know which approach they use?


I have found out that in default case they use 10 folds und also do standardization. Which kind of standardization? I would be very thankful if anyone can give me some more hints how they compute their lambda values.


1 Answer 1


Recommend viewing their tutorial here:

You will see that the function call you are looking for for getting the optimal $\lambda$ that minimizes the mean cross-validated error is cvmfit$lambda.min where lambda is a sequence of $\lambda$s. This means they are merely doing a grid-search, by solving the glmnet model for a sequence of $\lambda$s, and pin-pointing the minimum on that curve.

glmnet standardizes $y$ to have unit variance before computing its lambda sequence, also discussed in the tutorial.


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.