Repeated cross-validation for lambda and alpha with glmnet / glmnetUtils

614 Views Asked by At

I used mice to create some multiply imputed datasets:

library(glmnetUtils)
library(mice)

nhanes <- mice::nhanes
imp <- mice(nhanes)
com <- complete(imp, "long")

Using glmnetUtils, it is possible to cross-validate for both alpha and lambda simultaneously:

nhanes$hyp <- factor(nhanes$hyp)
fit <- cva.glmnet(hyp ~ ., data = nhanes, alpha = seq(0, 1, 0.05), family = "binomial")

Questions:

  • How could I run repeated cross-validation using glmnetUtils?
  • How can I parallelise the process? My real training dataset has 71,200 observations and takes approximately four hours to complete one run of cross-validation.
1

There are 1 best solutions below

0
On

To do parallel computation, you just need to follow the glmnetUtils manual. In your case, you can do something like the following.

numCores = detectCores(logical = FALSE) 
c1<-makeCluster(numCores)
fit <- cva.glmnet(hyp ~ ., data = nhanes, alpha = seq(0, 1, 0.05), family = "binomial",outerParallel=c1)