AnswerBun.com

ElasticNet coefficients are different for each cv.glmnet run

Cross Validated Asked by Jonathan on September 4, 2020

I am new to R and cv.glmnet. I have now tried to run my logistic model with ElasticNet instead of stepwise as people in this community suggest. But, I have troubles with the model itself as it keeps giving me different end results. I want to get alpha and lambda by letting cv.glmnet do this through minimization with a k-fold of 10. I learnt to set foldid equal to something in order to leave out the randomness in the coefficients, but I still get this randomness in my coefficients in the end of each run. All other answers to this question deals with a fixed alpha as here and here. This is my code

set.seed(123)
nfolds <- 10
foldid <- sample(1:10, size = length(y), replace=TRUE)
model <- lapply(1:10, function(i){
      cv.glmnet(trainX, trainY, type.measure = "deviance", family = "binomial", alpha = i, foldid = foldid, parallel = TRUE)
 })

Again, I do not want to fix my alpha and lambda, but surely get consistent coefficients when I run my Elastic model again and again. Can someone please tell me, what I am doing wrong here?

Add your own answers!

Related Questions

Dealing with singular fit in mixed models

2  Asked on December 25, 2021 by user33268

         

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP