0
$\begingroup$

I'm a beginner in elastic net. I'm using following code for elastic net in R

model <- train(
scaleSales_TT ~., data = train_data, method = "glmnet",
trControl = trainControl("cv", number = 10),
tuneLength = 10
)

In this setting I'm seeing 10 different alpha value & 10 different lambda value but after changing tunelength=20 I'm seeing 20 different alpha value & 18 different lambda value.I'm seeing that alpha values are equally spaced between 0.1 to 1 & gap between two apha values are determined using tune length. But I'm unable to find how lambda values are being estimated. Can you please help me understand?

$\endgroup$
4
  • $\begingroup$ Difficult without working data to see, but the lambda part of the grid is separated exponentially; i.e. if you sort the 18 values then each is a constant multiple of the preceding value. I would guess with tunelength=20 you saw a warning saying In nominalTrainWorkflow(x = x, y = y, wts = weights, info = trainInfo, : There were missing values in resampled performance measures and this led to you having 18 rather than 20 lambda values $\endgroup$
    – Henry
    May 28, 2019 at 9:26
  • $\begingroup$ Sorry, I can't able to share the data. Can you let me know how lamdas are generated using train function? I will try to map it with my data set $\endgroup$
    – Jesmin
    May 28, 2019 at 18:40
  • $\begingroup$ You should at least read the help page for glmnet (e.g. page 9 of cran.r-project.org/web/packages/glmnet/glmnet.pdf ) and another question on the maximum of lambda $\endgroup$
    – Henry
    May 28, 2019 at 20:27
  • $\begingroup$ tunelength isn't even mentioned in the pdf $\endgroup$ Dec 6, 2020 at 18:07

1 Answer 1

0
$\begingroup$

Quote from the function: caret::getModelInfo("glmnet")

function(x, y, len = NULL, search = "grid") { if(search == "grid") { out <- expand.grid(alpha = seq(0, 1, length = len), lambda = c(0, 10 ^ seq(-1, -4, length = len - 1))) } else { out <- data.frame(alpha = runif(len, min = 0, 1), lambda = 2^runif(len, min = -10, 3)) } out }

$\endgroup$

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.