Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python statsmodel.api logistic regression (Logit)

So I'm trying to do a prediction using python's statsmodels.api to do logistic regression on a binary outcome. I'm using Logit as per the tutorials. When I try to do a prediction on a test dataset, the output is in decimals between 0 and 1 for each of the records. Shouldn't it be giving me zero and one? or do I have to convert these using a round function or something.

Excuse the noobiness of this question. I am staring my journey.

like image 538
Karim Lameer Avatar asked Oct 19 '25 09:10

Karim Lameer


1 Answers

The predicted values are the probabilies given the explanatory variables, more precisely the probability of observing 1.

To get a 0, 1 prediction, you need to pick a threshold, like 0.5 for equal thresholding, and assign 1 to the probabilities above the threshold.

With numpy this would be for example

predicted = results.predict(x_for_prediction)
predicted_choice = (predicted > threshold).astype(int)
like image 186
Josef Avatar answered Oct 21 '25 22:10

Josef