Solved – Elastic net beta coefficients using Glmnet with Caret

caretcross-validationelastic netglmnetregression coefficients

In glmnet using caret my the model is trained and tuned by cross validation on my training set. I have a 10 fold cross validation, over a grid of 10 alphas and 10 lambdas. The best model chosen by glmnet is the model with the combination of alpha and lambda which has the best performance. This performance is an average over the 10 cross validation folds to reduce variance.

I then use the best model to predict outcome in unseen test data and compare the predictions against the actual test set outcome.

When I call up the best model's beta coefficients (see below) am I correct in my understanding that these coefficients are the average over the 10 cross validation folds?

coef(bestModel$finalModel, bestModel$bestTune$lambda)

The training and test split is often repeated to reduce variance in calculated model performance metric. When one repeats the initial 70:30 training/test split several times in an outer loop, models with different combinations of lambda and alpha often chosen and with different beta coefficients. I know I can average the performance metric but can I also average these models beta coefficients?
Given that such models commonly have different combinations of alpha and lambda.

Best Answer

yes, you are refitting the model with the lambda and alpha found by the cross-validation. You do not average across betas, you get the new ones. In the manual, you can see that the algorithm refits the final model enter image description here

Related Question