Binary Logistic Regression

Analyze data with two possible outcomes, such as the probability of a defect depending on temperature and pressure. Odds ratios show the effect of each factor, ROC/AUC and the confusion matrix show classification performance, and you can enter values in the results window to calculate the expected event probability.

1Data Table

Paste a table copied from Excel into a cell (Ctrl+V). Click a column header (A, B…) before pasting to use the first line as column names. Double-click a header to rename it, right-click to insert/delete rows and columns, and formulas such as =A1*2 work too.

2Binary Logistic Regression Options

Numeric predictors (multiple selection):
Categorical predictors (multiple selection, optional):

How to run a logistic regression

  1. Copy the binary outcome column and the predictor columns with their headers.
  2. Choose the outcome and the category treated as the event (1), then check the predictors. Set the classification threshold (default 0.5).
  3. Click Analyze, check the odds ratios and AUC, then enter values in the prediction box under the probability curve to get the event probability.

Worked example with sample data

The example data are the temperature (°C), pressure (bar), line (Line 1, 2) and result (Good/Defect) of 60 products. Result is the outcome with 'Defect' as the event (1), temperature and pressure are numeric predictors, and line is a categorical predictor.

Defect probability curve by temperature - other predictors fixed at their mean/mode, dashed line at the 0.5 decision threshold
Defect probability curve by temperature - other predictors fixed at their mean/mode, dashed line at the 0.5 decision threshold

The likelihood ratio test p=8.038e-12 shows the model is significant, with McFadden's pseudo R²=0.6622. The temperature odds ratio of 0.6833 means the odds of a defect fall by about 32% for each 1 °C increase, and Line 2 has 46.65 times higher odds of a defect than Line 1 (95% CI 2.262 ~ 962.1). Pressure is not significant (p=0.3684).

The probability curve shows the defect probability dropping quickly below 0.5 once the temperature passes about 204 °C. Enter a temperature and pressure in the prediction box under the curve and click Predict to get the defect probability and decision for those conditions.

AUC=0.9652 indicates excellent classification, and at the 0.5 threshold the accuracy is 0.8833, sensitivity 0.8788 and specificity 0.8889 (confusion matrix: 29 of 33 actual defects and 24 of 27 actual good products classified correctly).

How it is calculated

log(p/(1-p)) = b₀ + b₁X₁ + … is fitted with statsmodels Logit (maximum likelihood by Newton's method). Odds ratio = exp(coefficient); its confidence interval is the exponentiated normal-approximation (Wald) interval.

Model significance uses the likelihood ratio test (LLR p-value), and explanatory power uses McFadden's pseudo R² = 1 - log-likelihood / log-likelihood of the constant-only model. ROC/AUC and the calibration plot follow sklearn, and the confusion matrix counts a prediction as an event when the predicted probability exceeds the threshold.

What the results show

Probability curve (+ prediction box), coefficients and odds ratios, goodness of fit, confusion matrix table, ROC curve, calibration plot, confusion matrix heatmap and an odds ratio forest plot.

Interpreting the logistic regression

  • An odds ratio above 1 means the event probability rises as the predictor increases; it is significant when its confidence interval excludes 1.
  • An AUC of 0.5 is random guessing and 0.8 or higher is good classification.
  • Sensitivity is the share of actual events classified as events, and specificity is the share of actual non-events classified as non-events. Changing the threshold trades one for the other.

Frequently asked questions

What if the outcome has three or more values?

The category chosen as the event becomes 1 and every other category becomes 0.

Where do I predict probabilities?

Enter the numeric predictor values in the prediction box under the first panel (probability curve) of the results window and click Predict. Categorical predictors are fixed at their most frequent value.

The coefficients are extremely large.

If the predictors separate the outcomes perfectly (complete separation), the maximum likelihood estimate grows without bound, so the coefficients and standard errors become very large.

Other chart tools