Logit
Anonymous contributor
Published Dec 27, 2024
Contribute to Docs
Logit is a term used in statistics, specifically in the context of logistic regression. It represents the log-odds of a binary outcome, mapping probabilities from the 0 to 1 range to the entire real number line. The .Logit()
function is a key part of many statistical models, particularly in binary classification tasks.
Syntax
statsmodels.api.Logit(endog, exog)
endog
: The dependent (binary) variable, which must be a binary outcome (0 or 1).exog
: The independent variables (features or predictors).
Example
This example demonstrates how to use the .Logit()
function in the statsmodels
library to perform logistic regression:
import statsmodels.api as sm# Example dataX = sm.add_constant([[1], [2], [3], [4], [5]]) # Adding a constant for the intercepty = [0, 0, 1, 1, 1]# Fitting the logistic regression modelmodel = sm.Logit(y, X)result = model.fit()# Output the resultsprint(result.summary())
Note: The dependent variable (
y
) must contain only binary values (0 or 1) for the logistic regression to be valid.
This example produces a summary of the logistic regression model’s results, showing coefficients, standard errors, p-values, and other statistics relevant to evaluating the model fit:
Logit Regression Results==============================================================================Dep. Variable: y No. Observations: 5Model: Logit Df Residuals: 3Method: MLE Df Model: 1Date: Tue, 24 Dec 2024 Pseudo R-squ.: 1.000Time: 12:28:45 Log-Likelihood: -5.0138e-10converged: False LL-Null: -3.3651Covariance Type: nonrobust LLR p-value: 0.009480==============================================================================coef std err z P>|z| [0.025 0.975]------------------------------------------------------------------------------const -110.4353 2.23e+05 -0.000 1.000 -4.38e+05 4.38e+05x1 44.2438 9.07e+04 0.000 1.000 -1.78e+05 1.78e+05==============================================================================Complete Separation: The results show that there iscomplete separation or perfect prediction.In this case the Maximum Likelihood Estimator does not exist and the parametersare not identified.
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.