Does caret train function for glmnet cross-validate for both alpha and lambda?

Does the R caret package cross-validate over both alpha and lambda for the glmnet model? Running this code,

eGrid <- expand.grid(.alpha = (1:10) * 0.1,
.lambda = (1:10) * 0.1)

Control <- trainControl(method = "repeatedcv",repeats = 3,verboseIter =TRUE)

netFit <- train(x =train_features, y = y_train,
method = "glmnet",
tuneGrid = eGrid,
trControl = Control)


The training log looks like this.

Fold10.Rep3: alpha=1.0, lambda=NA


What does lambda=NA mean?

• How can I pass family="binomial" and type.measure="auc" to the glmnet model using train? – diugalde Jan 17 '17 at 20:38

train does tune over both.

Basically, you only need alpha when training and can get predictions across different values of lambda using predict.glmnet. Maybe a value of lambda = "all" or something else would be more informative.

Max

• How can I specify a sequence of alpha values? Without giving a lambda sequence? – diugalde Feb 3 '17 at 17:53
• Something like: alpha.seq = seq(0,1,.01) You do not need to use the exact method above. See caret documentation – Redeyes10 Apr 22 '17 at 21:58

Old question, but I recently had to deal with this problem and found this question as a reference.

Here is an alternative approach:

The glmnet vignette (https://web.stanford.edu/~hastie/glmnet/glmnet_alpha.html) specifically addresses this issue, recommending to specify the cross validation folds using the foldids argument and validate $\lambda$ over a grid of $\alpha$. This uses the same cv folds to validate $\lambda$ for each $\alpha$ in your grid.

The reason this may be superior to validating $\alpha$ and $\lambda$ simultaneously is that cv.glmnet validates $\lambda$ using a 'warm start' to select $\lambda$ rather than just randomly selecting $\lambda > 0$ i.e. speeding up validation and improving likelihood of have the optimal $\lambda$ in your grid (since fine grids are more computationally expensive).

• This is more recently the better answer – StephenBoesch Mar 25 '18 at 16:49