How to get odds-ratios and other related features with scikit-learn
<p>I'm going through this <a href="http://www.ats.ucla.edu/stat/mult_pkg/faq/general/odds_ratio.htm" rel="nofollow">odds ratios in logistic regression tutorial</a>, and trying to get the exactly the same results with the logistic regression module of scikit-learn. With the code below, I am able to get the coefficient and intercept but I could not find a way to find other properties of the model listed in the tutorial such as <em>log-likelyhood, Odds Ratio, Std. Err., z, P>|z|, [95% Conf. Interval]</em>. If someone could show me how to have them calculated with <code>sklearn</code> package, I would appreciate it.</p>

<pre><code>import pandas as pd
from sklearn import linear_model

url = 'http://www.ats.ucla.edu/stat/mult_pkg/faq/general/sample.csv'
df = pd.read_csv(url, na_values=[''])
y = df.hon.values
X = df.math.values
y = y.reshape(200,1)
X = X.reshape(200,1)
clf = linear_model.LogisticRegression(C=1e5)
clf.fit(X,y)
clf.coef_
clf.intercept_
</code></pre>

<p>In addition to @maxymoo's answer, to get other statistics, <code>statsmodel</code> can be used. Assuming that you have your data in a <code>DataFrame</code> called <code>df</code>, the code below should show a good summary:</p>

<pre><code>import pandas as pd
from patsy import dmatrices
import statsmodels.api as sm 

y, X = dmatrices( 'label ~ age + gender', data=df, return_type='dataframe')
mod = sm.Logit(y, X)
res = mod.fit()
print res.summary()
</code></pre>

python scikit-learn