I am using the cv.glmnet function from the glmnet library in R. I run the following function:
model = cv.glmnet(x = data, y = label, family = 'binomial', alpha = 0.1,type.measure = "auc")
From the following plot I expect to get an AUC between 0.62 and 0.64
However, when I pass the same data (i.e. the training data) to the predict function i.e.
pred = predict(fit, newx = data, type = 'class',s ="lambda.min")
auc(label,pred)
I only get back an AUC of 0.56.
I understand the random nature of the cross validation - but intuitively I would expect to get something back in the range suggested by the cross validation.
What have I missed here? Thanks in advance
I'm not sure how auc() works (it seems to be an internal function of glmnet), but you should try passing the predictions as a link or response instead of a class:
pred = predict(fit, newx = data, type = 'response',s ="lambda.min")
auc(label,pred)
class gives you the predicted class at a single response threshold (e.g., 0.5), while response gives you the probability which can be used to calculate the auc across the entire response function.