I was working through the lab on ridge regression and LASSO in ISLR and I came across a strange behavior in the cv.glmnet function. When I followed the lab as written I got the following

train <- sample(1:nrow(x), nrow(x)/2)
test <- (-train)
y.test <- y[test]
cv.out <- cv.glmnet(x[train,], y[train], lambda=grid, alpha=0)
bestlam <- cv.out$lambda.min
[1] 231.013

For my own benefit I tried it using a different seed (8675309) and got back a different result. Any combination of setting the seeds resulted in different answers. I am assuming this has to do with how the 10-folds are changed with the different seeds, however the different lambda.min can vary so much I am concerned the package might not be stable. Am I missing something?

  • 1
    $\begingroup$ Nice choice of different seed :D $\endgroup$ – Nick Stauner Jan 15 '14 at 4:18
  • $\begingroup$ Do the models indicated by the respective lambda.min for the different runs/seeds match - have similar included variables or coefs? Have you tried the lambda.1se option, which is the simplest model within 1 standard error of the best (lambda.min), which may be more stable, esp if the MSE is relatively flat around the "best" model. $\endgroup$ – Gavin Simpson Jan 15 '14 at 5:17
  • 1
    $\begingroup$ I think the point is the same as [here][1] [1]: stats.stackexchange.com/questions/97777/… $\endgroup$ – Alice Jun 12 '14 at 16:07
  • 1
    $\begingroup$ This question appears to be off-topic because it is specific to the GLMNET package in R. Those are generally off topic now, so I am voting to close my own question. $\endgroup$ – Fraijo Jul 30 '14 at 19:03
  • 1
    $\begingroup$ @Fraijo, I'd disagree--I think it's just on the topical side of the line, in that it's a question about the stuff implemented by GLMNET and not the syntax, etc. $\endgroup$ – Matt Krause Jul 30 '14 at 20:52

Browse other questions tagged or ask your own question.