# How to select a threshold for logistic regression in case of imbalance in class distribution [duplicate]

Consider the model

fit2 <- glm(y~x+z,data=records,family=binomial)

I have about 42000 records, of which close to 38000 belong to class y=0 and the remaining 4000 belong to class y=1. In order for me to compute the confusion matrix, I need to select a threshold t against which I need to compare the probabilities of the above model. How do I select this t?

Assuming my positive class to be the rare class, the risk of predicting a positive instance as negative is higher than the risk of predicting a negative instance as positive.

Should I use the threshold that maximizes sensitivity alone? or should I use the threshold that maximizes both sensitivity and specificity?

• OK, what I answered applys only to one-dimensional predictors. But you have two of them in your model, x and y. So your question is rather how to find some line of thresholds dividing the 2-dimensional plane spanned by x and y in two parts, right? Jan 15 '15 at 15:45