Lasso uses cross-validation to determine both the number of included predictors and the degree of shrinkage to avoid over-fitting. I have used the glmnet package to do this.

    cvob1= cv.glmnet(x,y) 

There is a high possibility that lambda1 and lambda2 are different. I need to get a proper lambda.min for the next step to obtain fitted values for the sparse solution to the model:


How can I decide which lambda to use? Should I repeat the cv.glmnet() for many times? How many time should I go for?


1 Answer 1


CV is a random process, which is why you are getting different lambda.mins. But they should be close to eachother. If you want a singular, reproducible lambda, try setting a seed:


  • $\begingroup$ would different lambdas affect my next step: coef(fit,s=cvob1$lambda.min) $\endgroup$
    – ay__ya
    Commented Mar 14, 2018 at 19:52
  • $\begingroup$ Yes, since different lambdas would yield different coefficients. (Remember large $\lambda$, small $\|\beta\|$). $\endgroup$ Commented Mar 15, 2018 at 11:13
  • $\begingroup$ setting a seed for cv.glmnet won't produce identical results unless the foldid's are set manually $\endgroup$
    – David
    Commented Feb 24, 2021 at 21:21

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.