I have a data set with n=199 observations and p=149 variables. I've tried to fit a lasso regression for reducing the number of variables in a logistic regression, but when i used it, I got that the best model have 0 variables. I don't know if my variables need to be standarized, or maybe my data set is too small.

My code is:


set.seed(914) ## number for reproducing
modelfitted<-glmnet(independent,dependent, family = "binomial",alpha = 1) #fitting the lasso regresssion
cv.modelfitted <- cv.glmnet(independent, dependent, type.measure = "class",family="binomial") ## C.V. for getting the best lambda.
coef(modelfitted,s=cv.modelfitted$lambda.min )

The output is

49 x 1 sparse Matrix of class "dgCMatrix"
(Intercept)                           -0.567521
capturing_times_on_page                .       
times_on_perfil                        .       
times_on_home                          .       
times_on_faq                           .       
times_on_terminos                      .       
times_on_privacidad                    .       
times_on_acerca                        .       
times_on_lugares_de_pago               .       
times_on_blog                          .       
times_on_contacto                      .       
times_on_libro_de_reclamaciones        .       
capturing_time_on_steps                .       
time_on_step1                          .       
time_on_step2                          .       
time_on_step3                          .       
time_on_step4                          .       
time_on_step5                          .       
time_on_subir_fotos                    .       
time_on_confimado                      .       
time_on_reintentar_subir_fotos         .       
amount_changes                         .       
time_changes                           .       
some rows were omitted.

PLOT of cv.modelfitted

The minimum miss classification error is for when the number of variables is zero. I hope that someone can help me. Why is this happening?


1 Answer 1


Your choice for the type.measure parameter might be posing a problem. Although classification error is one way to evaluate the cross-validations, a measure based on an all-or-none dichotomy can pose problems. The default, deviance, or AUC might be more useful. It's also possible that your choice of random-number seed was very unlucky; try a few others. Note that standardization is not the problem in your case as you didn't change the default in glmnet, which is to standardize predictor variables (see the manual page).

Another possibility, which you must consider seriously, is that your predictor variables (at least without some non-linear transformations) add nothing useful to the class predictions. The result of your analysis suggests that simply setting the prediction always to be the most frequent class might be the best, as it is correct with probability = 127/199, or 0.638. With 72 cases evidently in your least frequent class, it should be possible to get a LASSO model with 3 or 4 predictors returned, if you really have useful predictors.

  • 2
    $\begingroup$ #NeverAccuracy. $\endgroup$ Feb 4, 2017 at 3:29
  • $\begingroup$ @Edm, thanks for awnsering my question. I Thought that my random seed was very unlucky and I fitted the lasso regression 1000 times with differents random-number seed and the most common result was that the 40% of the cases with minimun error had 0 variables. Also, I thought that the AUC or default were better than Miss classification but i got similar results. You're right when you said that the problems could be in the predictors. I'll try to find a solution. $\endgroup$ Feb 5, 2017 at 4:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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