🧮 Brain Teaser

The Softmax That Forgets Its Past: Logistic Regression and Sufficient Statistics

Suppose you have binary labels y{0,1}y \in \{0, 1\} and a feature vector xRpx \in \mathbb{R}^p. You fit logistic regression, which models:

P(y=1x)=σ(βTx)=11+eβTx.P(y = 1 \mid x) = \sigma(\beta^T x) = \frac{1}{1 + e^{-\beta^T x}}.

Now consider a different scenario: you are told that within each class, the features are Gaussian with a shared covariance matrix:

xy=kN(μk,Σ),k=0,1,x \mid y = k \sim \mathcal{N}(\mu_k, \Sigma), \quad k = 0, 1,

with class priors πk=P(y=k)\pi_k = P(y = k).

The question: Using Bayes' theorem, compute P(y=1x)P(y=1 \mid x) under this generative (LDA) model. What do you notice? What does this say about the relationship between logistic regression and Linear Discriminant Analysis (LDA)?

Follow-up to ponder: LDA has more parameters than logistic regression. Does fitting more parameters make LDA better? When would LDA beat logistic regression, and when would it lose?

logistic regressionLDAGaussian generative modelBayes theorembias-variancediscriminative vs generative

Answer: LDA Is Secretly Logistic Regression

Key Idea / Intuition

The stunning fact is that when the class-conditional distributions are Gaussian with equal covariances, the posterior P(y=1x)P(y=1 \mid x) is exactly a logistic sigmoid of a linear function of xx — the same functional form as logistic regression. So LDA is a special case of logistic regression in terms of the decision boundary shape. The difference lies in how the parameters are estimated: LDA uses a generative model (more assumptions, more parameters to estimate), while logistic regression fits the boundary directly (fewer assumptions, estimates only β\beta). This tradeoff reveals a classical bias-variance story.


Formal Proof / Solution

Step 1: Apply Bayes' theorem.

P(y=1x)=P(xy=1)π1P(xy=1)π1+P(xy=0)π0.P(y=1 \mid x) = \frac{P(x \mid y=1)\, \pi_1}{P(x \mid y=1)\, \pi_1 + P(x \mid y=0)\, \pi_0}.

Dividing numerator and denominator by the numerator:

P(y=1x)=11+P(xy=0)π0P(xy=1)π1=σ ⁣(logP(xy=1)π1P(xy=0)π0).P(y=1 \mid x) = \frac{1}{1 + \dfrac{P(x \mid y=0)\, \pi_0}{P(x \mid y=1)\, \pi_1}} = \sigma\!\left(\log \frac{P(x \mid y=1)\, \pi_1}{P(x \mid y=0)\, \pi_0}\right).

Step 2: Plug in the Gaussian densities.

With xy=kN(μk,Σ)x \mid y=k \sim \mathcal{N}(\mu_k, \Sigma):

logP(xy=1)P(xy=0)=12(xμ1)TΣ1(xμ1)+12(xμ0)TΣ1(xμ0).\log \frac{P(x \mid y=1)}{P(x \mid y=0)} = -\tfrac{1}{2}(x-\mu_1)^T\Sigma^{-1}(x-\mu_1) + \tfrac{1}{2}(x-\mu_0)^T\Sigma^{-1}(x-\mu_0).

Expanding (the xTΣ1xx^T \Sigma^{-1} x terms cancel because Σ\Sigma is shared):

=xTΣ1(μ1μ0)12(μ1TΣ1μ1μ0TΣ1μ0).= x^T \Sigma^{-1}(\mu_1 - \mu_0) - \tfrac{1}{2}(\mu_1^T\Sigma^{-1}\mu_1 - \mu_0^T\Sigma^{-1}\mu_0).

Step 3: Collect into a linear form.

Define:

β=Σ1(μ1μ0),β0=12(μ1TΣ1μ1μ0TΣ1μ0)+logπ1π0.\beta = \Sigma^{-1}(\mu_1 - \mu_0), \qquad \beta_0 = -\tfrac{1}{2}(\mu_1^T\Sigma^{-1}\mu_1 - \mu_0^T\Sigma^{-1}\mu_0) + \log\frac{\pi_1}{\pi_0}.

Then:

P(y=1x)=σ(β0+βTx).\boxed{P(y=1 \mid x) = \sigma(\beta_0 + \beta^T x).}

This is exactly the logistic regression form.


Step 4: The punchline — what's different?

| | Logistic Regression | LDA | |---|---|---| | Model | P(yx)P(y \mid x) directly | P(xy)P(x \mid y), then invert | | Parameters estimated | βRp+1\beta \in \mathbb{R}^{p+1} | μ0,μ1,Σ,π\mu_0, \mu_1, \Sigma, \pi (many more) | | Assumes Gaussian xx? | No | Yes | | Decision boundary | Linear in xx | Linear in xx (same form!) |

Step 5: When does each win?

  • LDA wins when the Gaussian equal-covariance assumption is actually true: it uses the extra information from modeling P(xy)P(x \mid y), giving a lower-variance estimator of β\beta. LDA is more statistically efficient in this regime.

  • Logistic regression wins when the Gaussian assumption is wrong (e.g., binary features, skewed distributions): it makes no assumption on P(x)P(x), so its estimates are not biased by a false generative model. It is more robust.

This is the canonical efficiency vs. robustness tradeoff in statistics: parametric generative models win when correct, semiparametric discriminative models win when the generative assumptions fail. ESL (Section 4.3) calls this the "Analysis of the Difference Between LDA and Logistic Regression."


Bonus insight: If instead the covariances differ (Σ0Σ1\Sigma_0 \neq \Sigma_1), the xTΣ1xx^T \Sigma^{-1} x terms do not cancel, and the posterior becomes quadratic in xx — this is Quadratic Discriminant Analysis (QDA), which gives curved decision boundaries.

Source: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman, 2nd ed., Section 4.3

Type: ML/StatsSource: The Elements of Statistical Learning, Hastie, Tibshirani, Friedman, 2nd ed., Section 4.3Edit on GitHub ↗