Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordered Logit in Python?

I'm interested in running an ordered logit regression in python (using pandas, numpy, sklearn, or something that ecosystem). But I cannot find any way to do this. Is my google-skill lacking? Or is this not something that's been implemented in a standard package?

like image 790
exp1orer Avatar asked Jan 19 '15 23:01

exp1orer


2 Answers

If you're looking for Ordered Logistic Regression, it looks like you can find it in Fabian Pedregosa's minirank repo on GitHub.

(Hattip to @elyase, who originally provided the link in a comment on the question.)

like image 140
dmh Avatar answered Sep 19 '22 12:09

dmh


Update: Logit and Probit Ordinal regression models are now built in to statsmodels.

https://www.statsmodels.org/devel/examples/notebooks/generated/ordinal_regression.html

from statsmodels.miscmodels.ordinal_model import OrderedModel

Examples are given in the documentation above. For example:

import pandas as pd
from statsmodels.miscmodels.ordinal_model import OrderedModel
url = "https://stats.idre.ucla.edu/stat/data/ologit.dta"
data_student = pd.read_stata(url)

mod_log = OrderedModel(data_student['apply'],
                        data_student[['pared', 'public', 'gpa']],
                        distr='logit')

res_log = mod_log.fit(method='bfgs', disp=False)
res_log.summary()

The catch is that the development version of statsmodels is far ahead of the release. They say that installing the dev version of statsmodels is okay for everyday use. So I used the following:

pip3 install [email protected]:statsmodels/statsmodels.git

to do so.

like image 43
CPBL Avatar answered Sep 20 '22 12:09

CPBL