Logistic Regression
The log-likelihood, its convexity, the Hessian as a weighted Gram matrix, and what happens when the data is separable.
Model and likelihood
With and , the model is
The negative log-likelihood of an i.i.d. sample is
with
where .
is convex. It is strictly convex if and only if and no ; under those conditions the Hessian is positive definite.
- Initialise , so and .
- Repeat: compute and .
- Solve the weighted least-squares system .
- Update (optionally with a line search for robustness).
- Until is below tolerance.
Because is a weighted Gram matrix, each Newton step is a weighted least-squares solve — hence the name iteratively reweighted least squares. By the local quadratic convergence theorem, this converges in a handful of iterations when a maximiser exists.
Separability
Suppose there is with whenever and whenever . Then strictly decreasing as , so is not attained and along any minimising sequence.
Key idea
Unregularised logistic regression on separable data diverges. The standard fixes are ridge regularisation, which makes the objective coercive and restores a unique minimiser, or early stopping. But the direction of divergence is not arbitrary: Soudry et al. prove that converges to the maximum-margin direction — the hard-margin SVM solution. So gradient descent on the logistic loss implicitly performs margin maximisation. This is the cleanest rigorous instance of the implicit bias phenomenon discussed on the deep learning theory page, and it is worth knowing that the result is a genuine theorem in this setting, unlike its deep-network analogues.
At any stationary point, . In particular, if the design includes an intercept column of ones, : the predicted number of positives equals the observed number.
This is a real but limited form of calibration: it holds in-sample and only along the feature directions. It says nothing about out-of-sample calibration, and nothing about calibration within subgroups not expressible as feature directions — which is why post-hoc calibration methods (temperature scaling, isotonic regression) exist.
Problems
Convexity of the logistic lossProof · Beginner · 15 min Logistic regression diverges on separable dataProof · Intermediate · 30 min IRLS is a weighted least-squares solveProof · Intermediate · 30 min In-sample calibration of logistic regressionProof · Intermediate · 30 minReferences
- BookTrevor Hastie, Robert Tibshirani and Jerome Friedman (2009). The Elements of Statistical Learning
- BookPeter McCullagh and John A. Nelder (1989). Generalized Linear Models
- PaperDaniel Soudry, Elad Hoffer, Mor Shpigel Nacson, Suriya Gunasekar and Nathan Srebro (2018). The Implicit Bias of Gradient Descent on Separable Data
These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.
Results stated on this page
- PropositionThe logistic negative log-likelihood and its derivativesproof includedGradient equals the design matrix times the residual; Hessian is a variance-weighted Gram matrix.
- TheoremThe logistic loss is convex, and strictly convex iff the design has full rankproof includedConvexity follows from the PSD Hessian; strictness requires full column rank and non-degenerate probabilities.
- PropositionThe maximum likelihood estimate does not exist under separabilityproof includedIf the classes are linearly separable the likelihood has no maximiser and the norm of the iterates diverges.
- PropositionThe score equations enforce calibration on the feature directionsproof includedAt the optimum the predicted probabilities match the observed labels in every feature direction.
Problems (4)
All problemsPapers that use this mathematics
Dense Passage Retrieval for Open-Domain Question Answering
Vladimir Karpukhin, Barlas Oğuz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, Wen-tau Yih · 2020
Distributed Representations of Words and Phrases and their Compositionality
Tomas Mikolov, Ilya Sutskever, Kai Chen, Greg Corrado, Jeffrey Dean · 2013