Bayesian Logistic Regression
The Bayesian logistic regression model is
with the logistic sigmoid. The likelihood is
The Bernoulli likelihood is not conjugate to any standard prior on , so the posterior has no closed form. Three standard approaches:
- Laplace approximation — approximate the posterior by a Gaussian around the MAP:
The Hessian is closed form:
with and .- Metropolis-Hastings with Laplace proposal — use the Laplace Gaussian as a proposal distribution for MH. See 3.11.1 Metropolis-Hastings.
- Gibbs via Pólya-Gamma data augmentation — introduce latent variables so that the conditional posterior for given is Gaussian (Polson-Scott-Windle 2013). See 3.11.2 Gibbs Sampling.
MAP via Newton’s method (IRLS). The MAP optimization is convex in (log-concave posterior) and solved by Newton’s method:
Each Newton step is equivalent to a weighted least-squares fit against the working response with weights . This is iteratively reweighted least squares (IRLS), the standard frequentist logistic-regression solver, recovered here as a Bayesian MAP algorithm.Posterior predictive for a new input :
Under the Laplace approximation, a one-dimensional integral over remains, well-approximated by (MacKay’s probit approximation).
Prerequisites
- 3.1 Bayesian Framework — Bayesian mechanics.
- 3.8 Bayesian Regression — parent.
- 3.9 Laplace Approximation — the standard non-conjugate tool applied here.
- 2.4. Logistic Regression — frequentist counterpart for comparison.
Intuition
The sigmoid squashes a real-valued linear combination into a probability, and the Bernoulli likelihood pins each observed to that probability. Unlike the Gaussian likelihood, the sigmoid is not conjugate to Gaussian priors on — the log-likelihood is , which is not quadratic in , so prior-likelihood multiplication does not yield another Gaussian. But the log-posterior is concave, so it has a unique maximum, and near that maximum it is well-approximated by a quadratic — which is exactly the setup that makes the Laplace approximation accurate.
IRLS emerges because each Newton step re-expresses the log-likelihood around the current estimate as a weighted least-squares problem. The weights are smallest when is near 0 or 1 (confident predictions) and largest at (maximally uncertain), so ambiguous observations carry more Fisher information and pull the estimate harder. The Bayesian addition is the prior-precision term : regularized logistic regression (-penalty on ) is precisely the Bayesian MAP with a Gaussian prior, and the penalty strength is the prior precision.
The Laplace approximation is typically very accurate in this setting because the log-posterior is globally concave and the Hessian is well-defined and invertible wherever the design is not singular. The approximation fails when the posterior is multimodal (e.g., under separable data with strongly conflicting priors) or strongly skewed (rare in practice with and a proper Gaussian prior).
Properties
(Ridge-Regularized Logistic Regression as MAP) The -penalized logistic regression is the Bayesian MAP under a Gaussian prior.
The objective equals up to constants when the prior is . The Bayesian interpretation turns the penalty strength into a prior precision and gives a principled way to choose it (Type-II MLE / evidence maximization via Laplace; see 3.7 Marginal Likelihood).
(IRLS as Newton’s Method on the MAP) Each Newton step is a weighted least-squares fit.
Starting from , define working response and weights . Then
which is the Bayesian weighted-ridge normal equation. Convergence is quadratic near the MAP; the algorithm is numerically stable as long as the Hessian is well-conditioned, which the prior term guarantees even when is rank-deficient.
(Laplace Approximation is the Default Posterior) The Gaussian approximation around the MAP suffices for most inference tasks.
The posterior covariance is . Credible intervals for individual coefficients come from the diagonal of , exactly mirroring the frequentist Wald interval with as the inverse Fisher information. The Bayesian interpretation adds a coherent story for small samples, integrates naturally with hierarchical models, and provides proper posterior predictive distributions; the approximation’s accuracy is essentially identical to the Wald approximation in the frequentist literature.
(MacKay’s Probit Approximation for Posterior Predictive) The 1-D integral of a sigmoid against a Gaussian has a closed-form approximation.
accurate to about 0.2% for all . This reduces posterior prediction to a scalar sigmoid evaluation at a variance-corrected logit, avoiding any numerical integration. The “pull toward 0.5” as predictive variance grows is automatic: a Bayesian predictor is less confident than the MAP predictor precisely because it integrates over posterior uncertainty.
(Separable Data Gives Improper MLE, Proper Posterior) Classical logistic MLE is undefined when classes are linearly separable; the Bayesian posterior remains well-defined with any proper prior.
If there exists with iff , the log-likelihood is unbounded above (sending with gives perfect classification with zero loss), so the MLE does not exist. The proper Gaussian prior bounds ‘s magnitude and yields a unique MAP. This is one of the cleanest practical advantages of Bayesian logistic regression: regularization is built in and separable data is not a pathology.
(Pólya-Gamma Data Augmentation for Exact Gibbs) Introducing latent variables restores conditional Gaussianity.
Polson-Scott-Windle (2013) showed that the Bernoulli likelihood factor (with ) can be represented as where . Conditioning on , the likelihood for becomes Gaussian, enabling Gibbs updates with closed-form conditionals. This is the go-to MCMC method for Bayesian logistic regression when Laplace is not accurate enough.
(Posterior Variance Inflates Predictions Away From the Decision Boundary) Predictions are most uncertain near .
The posterior predictive probability curve, as a function of , is flatter than the plug-in curve — especially in regions where is large (test inputs far from training). A Bayesian predictor interpolates more cautiously into covariate regions where the training data is sparse, giving predictions that are closer to 0.5 than the MLE plug-in.
Examples
Example 1: Single-Covariate Logistic Regression via Laplace
Data with and . Prior .
IRLS: starting from , iterate Newton steps until convergence. Typically reaches in 4–5 iterations.
Hessian at MAP: , invertible by regularization.
Laplace posterior: ; marginal standard deviations .
Credible interval for : — excludes zero, consistent with the true coefficient 0.5.
Predictive at : , . MacKay approximation gives predictive probability — slightly pulled toward 0.5 compared with the plug-in .
Example 2: Separable Data Saved by the Prior
Data with a single covariate such that perfectly. The MLE does not exist: the likelihood grows as with .
With prior : the log-posterior is with . The prior penalty prevents from running off to infinity, and the MAP exists (typically –). The posterior is proper and concentrates around the MAP.
Predictions: at an input far from the training data (say ), the Laplace posterior gives predictive probability well short of 1 (perhaps 0.95 instead of the MLE’s 1 - ), reflecting genuine uncertainty about extrapolation.Classical logistic regression software either fails or silently returns an enormous MLE; the Bayesian model handles it without comment.
Example 3: Evidence-Based Tuning of the Prior Scale
The prior precision in controls regularization strength. Evidence-based tuning picks to maximize the Laplace-approximated marginal likelihood:
This is the logistic-regression analog of the evidence-framework procedure MacKay used for neural networks in the 1990s. For a typical dataset with , the evidence surface is unimodal in with maximum near –; cross-validation agrees to within a factor of 2. Unlike CV, evidence tuning requires no held-out splits and integrates naturally with model comparison across different feature sets.
Derivation
Goal: derive the Laplace posterior covariance from the Hessian of the log-posterior.
The log-posterior is
Differentiating twice with respect to : the first derivative is
with . The second derivative is
with using . The Hessian is negative-definite (log-posterior is concave), so the MAP is unique. The Laplace approximation is
The Newton iteration applied to this log-posterior is IRLS with prior-regularized weighted normal equations.
MacKay’s predictive approximation: for , approximate . This arises from approximating for , where is the standard-normal CDF, and then using the exact identity .
See Also
- 3.8 Bayesian Regression — parent index.
- 3.9 Laplace Approximation — underlying approximation technique.
- 3.8.4 Bayesian Poisson Regression — non-conjugate count-response counterpart.
- 3.11.1 Metropolis-Hastings — alternative inference via sampling, often with Laplace proposal.
- 3.11.2 Gibbs Sampling — Pólya-Gamma augmentation enables exact Gibbs.
- 3.7 Marginal Likelihood — evidence-based tuning of the prior precision.
- 2.4. Logistic Regression — frequentist counterpart.