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:

  1. Laplace approximation — approximate the posterior by a Gaussian around the MAP:

    The Hessian is closed form:

    with and .
  2. Metropolis-Hastings with Laplace proposal — use the Laplace Gaussian as a proposal distribution for MH. See 3.11.1 Metropolis-Hastings.
  3. 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

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

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