Bayesian Regression

Every loss is a likelihood. Every regularizer is a prior. Least squares, ridge, LASSO, and best-subset selection are MAP estimates under four different probabilistic models.

1. The dictionary

The MAP estimate maximises the posterior, or equivalently minimises its negative log:

$$ \hat\beta_{\text{MAP}} \;=\; \arg\max_\beta\;\log p(y\mid X,\beta) + \log p(\beta) \;=\; \arg\min_\beta\;\bigl[\,-\log p(y\mid X,\beta)\,\bigr] + \bigl[\,-\log p(\beta)\,\bigr]. $$

The first bracket is a data-fit loss; the second is a regularizer. Read the equation in reverse and every penalised-likelihood method you already know turns into a Bayesian model:

Frequentist pieceBayesian piece
loss $\;\ell(y, X\beta)$$-\log p(y\mid X,\beta)$  (likelihood)
regularizer $\;\lambda\,R(\beta)$$-\log p(\beta)$  (prior)
regularization strength $\lambda$ratio of noise variance to prior variance
$\arg\min$ (loss + penalty)MAP estimate

That is the entire trick. The four sections below just instantiate it for specific choices of likelihood and prior.

2. Worked case: ridge is Gaussian MAP

Use Gaussian observation noise and an independent Gaussian prior on each coefficient:

$$ \begin{aligned} y_i &= x_i^\top\beta + \varepsilon_i,\qquad \varepsilon_i \sim \mathcal N(0,\sigma^2),\\ \beta_j \;\sim\; \mathcal N(0, \tau^2) \end{aligned} $$

The Gaussian log likelihood gives squared error. The Gaussian log prior gives an $\ell_2$ penalty. Dropping constants and multiplying by $2\sigma^2$ leaves the ridge objective:

$$ \hat\beta_{\text{ridge}} \;=\; \arg\min_\beta\;\sum_i (y_i - x_i^\top\beta)^2 \;+\; \lambda\sum_j \beta_j^2, \qquad \lambda \;=\; \frac{\sigma^2}{\tau^2}. $$

The regularization strength is the ratio of noise variance to prior variance. Tight prior (small $\tau^2$) means strong shrinkage; vague prior (large $\tau^2$) means $\lambda\to 0$ and ridge collapses back to OLS. The other three rows in the dictionary below follow by changing either the likelihood (the loss) or the prior shape near zero (the penalty).

Why ridge shrinks but doesn't select. The Gaussian log-density $-\beta_j^2/2\tau^2$ is differentiable and flat at zero: its slope there is $0$. A small coefficient incurs vanishingly small penalty, so the optimum sits at the place where the likelihood gradient balances the prior gradient. That balance point is generically nonzero. The estimator pulls every coefficient toward zero but stops short of the axis.

3. Three estimators side by side

Slide $\beta_{\text{OLS}}$ and watch the three estimators respond. The top panel plots the negative log posterior (the thing being minimised), with a small inset showing the prior penalty shape; the bottom panel plots the resulting $\hat\beta$ as a function of $\beta_{\text{OLS}}$. Ridge is a straight line through the origin with slope $1/(1+\lambda)$, proportional shrinkage. LASSO is a soft threshold: a flat dead zone of width $\lambda$ around the origin, then a line of slope $1$ shifted toward zero by $\lambda/2$. L0 is a hard threshold: identity outside $\pm\sqrt\lambda$, exact zero inside.

Figure 1 · Shrink, soft-threshold, and hard-threshold side by side
ridge (L2 / Gaussian prior) LASSO (L1 / Laplace prior) L0 (spike-and-slab) $\beta_{\text{OLS}}$ reference
$\beta_{\text{OLS}}$: 1.60
$\lambda$: 0.80

Things to notice as you drag:

4. The four-row dictionary

Estimator Loss + penalty Noise model Prior on $\beta_j$ Behaviour at $\beta_j = 0$
OLS $\sum(y_i - x_i^\top\beta)^2$ Gaussian noise flat (improper) no shrinkage
ridge $\;\;+\;\lambda\sum\beta_j^2$ Gaussian noise $\mathcal N(0,\tau^2)$ smooth shrinkage, never exactly $0$
LASSO $\;\;+\;\lambda\sum|\beta_j|$ Gaussian noise $\text{Laplace}(0,b)$ kink at $0$ → exact zeros + shrinkage
best subset $\;\;+\;\lambda\|\beta\|_0$ Gaussian noise spike-and-slab discrete in/out, no shrinkage when in

5. LASSO lands on axes because diamond constraints have corners

The 1-D picture above shows soft- vs hard-thresholding cleanly, but it doesn't yet show which coefficient LASSO zeros out when there's more than one to choose from. For that, the canonical picture is the 2-D constraint-region view. Write each estimator as a constrained problem:

$$ \min_\beta\;\sum_i (y_i - x_i^\top\beta)^2 \quad\text{subject to}\quad \|\beta\|_q \le s, \qquad q \in \{0, 1, 2\}. $$

The OLS objective's level sets are ellipses centred at $\beta_{\text{OLS}}$. The MAP estimate is the point of the smallest such ellipse that still touches the feasible region. Three regions, three touch geometries:

Figure 2 · OLS ellipses meet L0 (axes), L1 (diamond), L2 (disk)
L2 disk (ridge) L1 diamond (LASSO) L0 axes (best subset) $\beta_{\text{OLS}}$ (drag me)
constraint radius $r$: 1.00
OLS correlation: 0.00

Drag the OLS point around. Things to notice:

6. The shape-near-zero intuition

The whole story is in the picture of the log-prior near the origin. Three curves, three behaviours:

Once you see the four estimators as MAP under four priors, several familiar facts stop looking arbitrary:

7. MAP discards posterior spread

MAP collapses the posterior to its mode, which means it ignores everything else the prior was telling you. Two specific costs are worth flagging:

What next