22
$\begingroup$

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?

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

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

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

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).

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ This is more recently the better answer $\endgroup$ – StephenBoesch Mar 25 '18 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.