# Does it make sense to calculate cross validation test error for a logistic model that has been ridge regressed?

I am working with the famous white wine dataset, and I am trying to fit a logistic model on it, where I also perform ridge regression on this logistic model. Finally, I want to calculate the test error of this model using 10 fold CV. Does this make sense? I ask because trying to do this with R seems to not be easily possible. Here is my code -

# Data pre-processing
winedata <- read.delim("winequality-white.csv", sep = ';')
winedata$$quality[winedata$$quality< 7] <- "0" #recode
winedata$$quality[winedata$$quality>=7] <- "1" #recode
winedata$$quality <- factor(winedata$$quality)# Convert the column to a factor
names(winedata)[names(winedata) == "quality"] <- "good"      #rename 'quality' to 'good'

# I then used 10 fold C to find the best value for lambda for Ridge regression, not adding the code for that here
ridge.model <- glmnet(x, y, alpha = 0, family = "binomial", lambda = bestlam) # fit logistic model with ridge regression. This is the model I want finally
ridge.model.cv.err<- cv.glmnet(x,y, lambda = bestlam, cost1, K=10) # trying to calculate the 10 fold CV of the final model. THIS GIVES ERROR
ridge.model.cv.err$delta # this is what I hoped would give me the test error  This gives the error - Error in cv.glmnet(x, y, lambda = bestlam, cost1, K = 10) : Need more than one value of lambda for cv.glmnet Am I doing something very wrong here, something that doesn't make sense? • what does it mean to perform ridge regression on the logistic model? Is it L2 regularization over the logistic model that you've meant? Apr 4, 2020 at 20:24 • @gunes, I think it would be thought as penalized logistic regression, where I specify the lambda value that specifies the coefficient shrinkage. I calculated this optimum lambda value by doing 10 fold CV for ridge regression on the data Apr 4, 2020 at 20:34 • I read about Penalized Logistic Regression here - sthda.com/english/articles/36-classification-methods-essentials/… Apr 4, 2020 at 20:40 • I think it’s telling you to give all ten$\lambda\$ values. What happens if you give it rep(lambda, 10)?
– Dave
Apr 4, 2020 at 21:07
• @Dave number of folds is irrelevant to the number of different lambda values Apr 4, 2020 at 21:24

Finding best $$\lambda$$ from Ridge Regression and using it in logistic regression is not a good idea. Optimisation objectives significantly differ between the two models. You need to find the best $$\lambda$$ for the penalised logreg.
• Maybe you can set lambda = c(1,1+1e-12) and get your error. Such a small deviance in lambda wouldn't produce a different error. This is hacky, and there are probably better ways to do it (other than coding the cv yourself), but I'm not extremely familiar with glmnet. Apr 4, 2020 at 21:19