0

I ran cv.glmnet using a Poisson distribution for a binary outcome. The predict function returns predicted probabilities, but not predicted classes. How do I convert the probabilities into classes so I might generate a confusionMatrix to determine AUC, etc.? NB. At least one predicted probability is > 1.

cv <- cv.glmnet(deriv.x, deriv.y, foldid = foldid, weights = wts, family = "poisson")
pred <- predict.cv.glmnet(cv, newx = valid.x, s = "lambda.min", "response")
confusionMatrix(pred, valid.y)
Error in confusionMatrix.default(pred, valid.y) : 
  the data cannot have more levels than the reference
C_H
  • 191
  • 14
  • 1
    check [this](https://stats.stackexchange.com/questions/38004/poisson-regression-for-binary-data) to see why it is a bad idea to use poisson regression for binary data – missuse Nov 14 '17 at 12:43

1 Answers1

0

It's because you're returning probabilities, not classes, so try it:

cv <- cv.glmnet(deriv.x, deriv.y, foldid = foldid, weights = wts, family = "poisson")
pred <- predict.cv.glmnet(cv, newx = valid.x, s = "lambda.min", "response")

pred <- ifelse(pred > 0.5,1,0) 

confusionMatrix(pred, valid.y)

You can choose your own value for rounding off.

AntonCH
  • 272
  • 2
  • 3
  • 13