logit is a statsmodels formula API function for specifying a logistic regression from a dependent variable, predictors, and a data frame. Calling fit() estimates model parameters, while summary() reports coefficients, p-values, and goodness-of-fit statistics. section 5.2.2
Raisin variety classification
A model regresses Class against morphological measurements including Area, MajorAxisLength, MinorAxisLength, Eccentricity, ConvexArea, Extent, and Perimeter. The overall LLR p-value is 0, supporting discriminatory value, but Eccentricity and Extent have nonsignificant p-values and motivate model reduction. section 5.2.2
>>> import statsmodels.formula.api as smf
>>> log_model = smf.logit('Class ~ Area + '
>>> 'MajorAxisLength + '
>>> 'MinorAxisLength + '
>>> 'Eccentricity + '
>>> 'ConvexArea + '
>>> 'Extent + '
>>> 'Perimeter', data = raisins).fit()
>>> print(log_model.summary())
Optimization terminated successfully.
Current function value: 0.338384
Iterations 9
Logit Regression Results
===========================================================================
Dep. Variable: Class No. Observations: 900
Model: Logit Df Residuals: 892
Method: MLE Df Model: 7
Date: Wed, 27 Mar 2024 Pseudo R-squ.: 0.5118
Time: 15:03:56 Log-Likelihood: -304.55
converged: True LL-Null: -623.83
Covariance Type: nonrobust LLR p-value: 1.196e-133
===========================================================================
coef std err z P>|z| [0.025 0.975]
---------------------------------------------------------------------------
Intercept -2.6642 7.028 -0.379 0.705 -16.439 11.111
Area 0.0005 0.000 4.027 0.000 0.000 0.001
MajorAxisLength
-0.0447 0.016 -2.801 0.005 -0.076 -0.013
MinorAxisLength
-0.0899 0.027 -3.342 0.001 -0.143 -0.037
Eccentricity
-3.5248 4.909 -0.718 0.473 -13.147 6.097
ConvexArea
-0.0004 0.000 -3.446 0.001 -0.001 -0.000
Extent -0.6051 2.697 -0.224 0.822 -5.891 4.681
Perimeter 0.0361 0.007 5.464 0.000 0.023 0.049
Inspect the complete formula, fitting call, optimization output, and regression summary for the multiple logistic model. section 5.2.2
