New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
glmnet lambdas #116
Comments
What happens if you take the default lambdas (100) and explicitly pass them them to One idea would be to have caret use |
If you run glmnet and then get the lambdas out and plug them back in to run it again it works fine and takes exactly the same amount of time. The problem is that the full lambda sequence in determined in the Hastie's underlying fortran code. I've just been using tuneGrid and guessing at a good sequence if I'm going to use glmnet with caret. Setting a higher tuneLength expands alpha as well, which isn't desirable. Thanks |
I wonder if we could write a function that would approximate Hastie's underlying fortran code and take the guesswork out of finding a good lambda sequence. If we can do that, I think we can put it into caret. |
The default code that you mention:
is really for the default grid. Instead of going the fortran route, we can do something along the lines of the While this isn't that computationally effective, note that One solution might be to have the
If you are going to fit a granular grid of lambda values, the computational expense of the initial |
I just did some testing on moderately sized data sets. First, doing an initial Second, it fits a lot of bad models, at least for the three disparate cases that I tried. The path includes a lot of models with really large lambda values that regularize the crap out of the coefficients. That doesn't mean it will never work but I would never try values of lambda in the thousands. There is code below for one example from APM*. The others that I tried use Pfizer data. Third, this does expose a design flaw in the package. I should have passed Overall, I think this would be a good idea for making the default grid. It might make sense, for small values of
|
Ug. I forgot about I'll try this on some other examples too be here is the APM example again:
|
I'm going to check in code that uses the function below with Test as you see fit... function(x, y, len = NULL) {
numLev <- if(is.character(y) | is.factor(y)) length(levels(y)) else NA
if(!is.na(numLev)) {
fam <- ifelse(numLev > 2, "multinomial", "binomial")
} else fam <- "gaussian"
init <- glmnet(as.matrix(x), y,
family = fam,
nlambda = len+2,
alpha = .5)
lambda <- unique(init$lambda)
lambda <- lambda[-c(1, length(lambda))]
lambda <- lambda[1:min(length(lambda), len)]
expand.grid(alpha = seq(0.1, 1, length = len),
lambda = lambda)
} |
added to the package |
I noticed that when running glmnet with caret it seems to use fixed lambdas. A huge portion of the time it seems like I get 0.1 as the lambda selected. There may very well be a good reason for this but I know that using discrete lambdas is often not faster than running the full regularization path. In addition I've seen cases where I get better performance with cv.glmnet.
Natively glmnet uses this to logic to decide the minimum lambda:
And currently this is the code in the caret glmnet grid function:
This is just some benchmarking I did with a built dataset.
Changing alpha=1 is 7.47 sec for the full set of lambdas or 1.41 sec for lambda 0.001.
Anyway I was just wondering if there is a reason for this or if in the future we might be able to think about having glmnet in caret run with the native lambda. I know that the obvious workaround to get more glmnet like set of lambdas is to specify tuneGrid in train manually.
Thanks for the feedback,
Reynald
The text was updated successfully, but these errors were encountered: