Logistic Regression

1. Sigmoid Function

- logistic function

- Hyperbolic tangent

alt text

2. odds ratio

3. Parameter estimation (Log Likelihood)

4. pseudo R square (likelihood ratio R square)

where

5. Logistic Regression Report

import pandas as pd
import numpy as np
df = pd.read_csv("http://www.stat.tamu.edu/~sheather/book/docs/datasets/MichelinNY.csv", encoding="latin1")
x = df.drop(['InMichelin', 'Restaurant Name'], axis=1)
y = df.InMichelin
import statsmodels.api as sm
from scipy import stats
stats.chisqprob = lambda chisq, df: stats.chi2.sf(chisq, df)

logit_model=sm.Logit(y,x)
result=logit_model.fit()
print(result.summary())
Optimization terminated successfully.
         Current function value: 0.547718
         Iterations 7
                           Logit Regression Results                           
==============================================================================
Dep. Variable:             InMichelin   No. Observations:                  164
Model:                          Logit   Df Residuals:                      160
Method:                           MLE   Df Model:                            3
Date:                Fri, 04 May 2018   Pseudo R-squ.:                  0.2043
Time:                        20:42:00   Log-Likelihood:                -89.826
converged:                       True   LL-Null:                       -112.89
                                        LLR p-value:                 5.303e-10
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
Food           0.0211      0.107      0.198      0.843      -0.188       0.230
Decor         -0.0357      0.078     -0.460      0.646      -0.188       0.117
Service       -0.3272      0.121     -2.702      0.007      -0.565      -0.090
Price          0.1349      0.028      4.864      0.000       0.081       0.189
==============================================================================

Reference

Logistic Regression - wikipedia

로지스틱회귀 - ratsgo’s blog


© 2018. All rights reserved.

Powered by Hydejack v7.5.0