2
$\begingroup$

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

set.seed(1)
train <- sample(1:nrow(x), nrow(x)/2)
test <- (-train)
y.test <- y[test]
set.seed(1)
cv.out <- cv.glmnet(x[train,], y[train], lambda=grid, alpha=0)
plot(cv.out)
bestlam <- cv.out$lambda.min
bestlam
[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?

$\endgroup$
7
  • 1
    $\begingroup$ Nice choice of different seed :D $\endgroup$ Commented Jan 15, 2014 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$ Commented Jan 15, 2014 at 5:17
  • 1
    $\begingroup$ I think the point is the same as [here][1] [1]: stats.stackexchange.com/questions/97777/… $\endgroup$
    – Alice
    Commented Jun 12, 2014 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
    Commented Jul 30, 2014 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$ Commented Jul 30, 2014 at 20:52

0

Browse other questions tagged or ask your own question.