Having read this link, I know that it is important to fix the CV sample using the foldid argument when tuning the $\alpha$ parameter incv.glmnet.

Question: How does one define an optimal $\alpha$?

Question: And how is the optimal $\alpha$ selected ?

Taking into account of the foldid issue, I ensured I used the same CV sample throughout. (See sample code below). Then I tried fixing the value of $\alpha$ first and then found the optimal both $\lambda_{min}$ and the optimal $\lambda_{`1SE}$ and then looped through the remaining values of $\alpha$ and then selected the model with optimal $\lambda_{min}$ and $\lambda_{1SE}$? This approach seems to give different results for different CV samples. And hence , unstable whether I choose to $\lambda_{min}$ or $\lambda_{1SE}$.

l               = 25
foldid          = sample(1:k_fold, size=length(y_train),replace=T)
alpha_list      = seq(0,1,length.out=l)
en              = lapply(alpha_list, function(aa,cv_id){
                                      res <- cv.glmnet(foldid=cv_id,alpha = aa, 
                                      return(res$cvm[which(res$lambda ==res$lambda.min)])

res             = matrix(NA,nrow=l,ncol=2)
res[,1]         = alpha_list
res[,2]         = unlist(en)
plot(x=res[,1],y=res[,2],type="l",col="red",xlab="Alpha",ylab="CV ESPE")

enter image description here

I know that caret does it all but honestly, I couldn't find a proper documentation of how caret specifically tunes these 2 parameters for the glmnet and based on what criteria it does the tuning?


Your Answer

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

Browse other questions tagged or ask your own question.