Logistic Regression (ML)

Machine Learning
Introduced by
Cox, D. R.
Year
1958
Type
Probabilistic linear classifier
Family
Machine learning

What does it do?

Logistic regression is a probabilistic classifier that models the log-odds of a binary (or multinomial) outcome as a linear function of the predictors.

The binary-sequence regression problem on which the model is based is treated in D. R. Cox's 1958 paper, which is the reference cited for it on this page. It is widely used in statistics and machine learning, valued for its probability outputs and for coefficients that can be read as changes in log-odds.

The intuition behind the method

Logistic regression asks: given a set of features, what is the probability that an observation belongs to a particular class? It fits a straight line to the log-odds of the outcome, then passes that linear score through a sigmoid (S-shaped) curve to produce a probability between 0 and 1. Each predictor's coefficient gives the change in the log-odds of the positive class associated with a one-unit increase in that feature, holding the other predictors constant, which is what makes the model easy to inspect. A predicted probability of 0.5 or more is classified as the positive class by default, though this threshold can be changed.

History

D. R. Cox's 1958 paper, The Regression Analysis of Binary Sequences, considered problems in which the chance that a trial is a 1 depends on one or more independent variables, and it reviewed earlier work on this setting. Cox's paper is the reference for the model used here. Later extensions add L1 or L2 penalties to the likelihood to control overfitting and the size of the coefficients; these penalised variants are now standard in machine-learning software.

When to use it

Use logistic regression when the outcome is binary or a multi-class outcome without a natural order, when there are at least about 10 events per predictor (a rule of thumb), and when interpretable coefficients or probability estimates are needed. It is a common baseline classifier in many fields and is worth fitting before more complex models. Avoid it when the decision boundary is strongly nonlinear and would need many hand-built interaction or polynomial terms, or when predictive accuracy on complex tabular data matters more than interpretability. In those cases tree-based ensembles or SVMs are often the better choice.

Limitations and considerations

  • Assumes a linear relationship between features and the log-odds of the outcome; nonlinear patterns require manual feature engineering or a nonlinear model.
  • Sensitive to multicollinearity among predictors: correlated features inflate coefficient standard errors and make the individual coefficient estimates unstable.
  • Requires enough events per predictor (rule of thumb: at least 10); sparse outcome classes cause convergence problems and overfitting.
  • May underperform ensemble methods (random forest, gradient boosting) on complex tabular data with many interactions.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Produces class probabilities, not just labels, which can be used for ranking and for setting a decision threshold.
  • Coefficients are interpretable as log-odds ratios, which suits clinical, social-science, and policy reporting where odds ratios are expected.
  • Computationally fast and memory-efficient even on large datasets.
  • Regularised variants (Ridge, Lasso, Elastic Net) can handle many predictors and, with L1 penalties, perform automatic feature selection.
  • Makes fewer distributional assumptions than discriminant analysis: it does not require the predictors to be multivariate normal.
  • Simple enough that its predictions can be checked against a transparent formula, which makes it a useful reference point when comparing more complex models.

Applications

  • Disease diagnosis and clinical risk scoring (e.g., predicting readmission or mortality).
  • Credit risk and fraud detection in finance.
  • Binary survey-response modelling in social science and epidemiology.
  • Spam and sentiment classification as a fast, interpretable text baseline.
  • Baseline classifier before deploying more complex ensemble models.

How it works

How it works

1

A weighted sum of all input features is computed. Each feature receives a coefficient (weight) that is learned from data; the intercept captures the baseline log-odds when all features are zero. This is identical in form to linear regression but the output is interpreted as a log-odds score rather than a direct numeric prediction.

Formula
z = \beta_0 + \beta_1 x_1 + \cdots + \beta_p x_p
2

The linear score is transformed by the sigmoid function, which maps any real number to the open interval (0, 1). This gives a well-calibrated class probability. For more than two unordered classes, the same linear scores are normalised across alternatives with the softmax form P(y=j|x) = exp(β_j'x) / Σ_k exp(β_k'x), which is the standard logit choice probability (Croissant, Microeconometrics with R, 2024, section 14.4.1), so that the probabilities sum to one over all classes.

Formula
P(y=1|\mathbf{x}) = \sigma(z) = \frac{1}{1 + e^{-z}}
3

Model parameters are estimated by maximising the log-likelihood of the observed labels given the predicted probabilities. This is equivalent to minimising binary cross-entropy loss. Unlike ordinary least squares, there is no closed-form solution: an iterative optimisation algorithm (typically Newton–Raphson or gradient descent) is used.

Formula
\ell(\boldsymbol{\beta}) = \sum_{i=1}^{n} \left[ y_i \log \hat{p}_i + (1-y_i) \log(1-\hat{p}_i) \right]
4

An iterative solver — such as L-BFGS, Newton–Raphson, or stochastic gradient descent — updates the coefficient vector until convergence. Regularisation terms (L1 or L2) can be added to the objective to shrink coefficients, preventing overfitting and enabling automatic feature selection (L1 / Lasso).

5

The fitted probability is compared to a classification threshold (default 0.5) to assign a class label. In imbalanced settings or when false-positive and false-negative costs differ, this threshold should be tuned using a precision-recall curve or ROC analysis rather than left at 0.5.

Formula
\hat{y} = \mathbf{1}[\hat{p} \geq 0.5]

Common pitfalls

  • Reporting performance on the same data used to estimate the coefficients or to choose the 0.5 threshold, which inflates apparent accuracy. Use a held-out test set or cross-validation.
  • Using accuracy as the sole metric with imbalanced classes instead of reporting AUC-ROC, F1, and a confusion matrix.
  • Ignoring the linearity assumption and applying logistic regression to data with strongly nonlinear class boundaries without diagnostic checks.
  • Failing to apply regularisation when the number of predictors is large relative to the number of events, leading to overfitting.
  • Not checking for multicollinearity (via VIF) before interpreting coefficient magnitudes.
  • Ignoring perfect or quasi-complete separation, where a predictor or combination of predictors splits the classes exactly. The maximum-likelihood estimates then fail to converge and the coefficients are not meaningful.

Frequently asked questions

When should I prefer logistic regression over a random forest?

When you need calibrated probabilities, interpretable coefficients, or must satisfy reporting standards that require explicit odds ratios, as in clinical trials or policy evaluation. Random forests often achieve higher predictive accuracy but provide no direct coefficient interpretation.

How many observations do I need?

A widely cited rule of thumb is at least 10 events (positive outcomes) per predictor variable. With fewer events, parameter estimates become unstable and confidence intervals unreliable. Regularisation or penalised likelihood can extend the usable range somewhat.

Should I standardise my features?

Standardising features is not required for prediction, but it is important when comparing coefficient magnitudes across predictors or when using regularisation (L1 or L2), because penalties treat all coefficients on the same scale.

What is the difference between binary and multinomial logistic regression?

Binary logistic regression models a two-class outcome using the sigmoid function. Multinomial (softmax) logistic regression generalises this to three or more unordered classes, estimating one set of coefficients per class relative to a reference class.

How do I handle class imbalance?

Reweight the loss so that errors on the minority class count more, or resample the training data. Evaluate with AUC-ROC and precision-recall curves rather than accuracy alone, and choose the classification threshold on a validation set rather than leaving it at 0.5.

Related methods

Sources

  1. Cox, D. R. (1958). The regression analysis of binary sequences. Journal of the Royal Statistical Society, Series B, 20(2), 215–242.

    Open DOI reference
  2. James, G., Witten, D., Hastie, T. & Tibshirani, R. (2013). An Introduction to Statistical Learning (Ch. 4). Springer.

    ISBN: 978-1-4614-7138-7
  3. Croissant, Yves - Microeconometrics with R (2024, CRC Press), section 14.4.1 (standard logit choice probability; page number not recorded in the library extract)