Skip to content
Advertisement

beta coefficients and p-value with l Logistic Regression in Python

I would like to perform a simple logistic regression (1 dependent, 1 independent variable) in python. All of the documentation I see about logistic regressions in python is for using it to develop a predictive model. I would like to use it more from the statistics side. How do I find the Odds ratio, p-value, and confidence interval of a simple logistic regression on python?

JavaScript

with an ideal output of Odds ratio, p-value, and confidence interval

Advertisement

Answer

I assume you are using LogisticRegression() from sklearn. You don’t get to estimate p-value confidence interval from that. You can use statsmodels, also note that statsmodels without formulas is a bit different from sklearn (see comments by @Josef), so you need to add a intercept using sm.add_constant() :

JavaScript

The coefficient is in log odds, you can simply convert that to odds ratio. The [0.025 0.975] columns are the 95% confidence interval for the log odds. Check out help page for more info

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement