Basic Prerequisites: 02 · Bayes’ Theorem & Priors and Multivariable Calculus.


1. Intuition & Practical Objective

Every penalty you have ever seen in machine learning is a prior in disguise. Ridge regression’s is the negative log of a Gaussian prior on the coefficients; lasso’s is the negative log of a Laplace prior. The regularized estimate is the MAP estimate of a Bayesian model, and is a ratio of the observation noise to the prior spread, - not a free knob to be tuned blindly.

This page makes that correspondence exact, because it is the single cleanest bridge between the two halves of applied statistics. Once you see it, terms like “shrinkage”, “weight decay”, and “sparsity” stop being tricks and become statements about the prior you assumed.

The one-sentence essence. “MAP ; write and the prior is the penalty - Gaussian ridge (), Laplace lasso (), and is the noise-to-prior precision ratio.”


2. Mathematical Ground Truth & Derivations

The master identity (ESL §3.4, §8.3). For iid Gaussian data and prior ,

Minimizing the posterior loss = minimizing RSS plus the negative log-prior. The prior is the penalty.

Gaussian prior ridge . With ,

The closed form is the ridge normal equation

A diffuse prior (, ) recovers OLS; a tight prior shrinks coefficients toward 0. Additivity of to is precisely the additive-precision result of 02 applied to the whole coefficient vector - and it is also why ridge fixes the singular that makes OLS ill-posed (the ridge page of Covariance Shrinkage uses the same move on ).

Laplace prior lasso . With , , so

Solved by coordinate descent with the soft-thresholding operator :

Why the Laplace prior gives exact zeros: its log-density has a kink at 0, so the negative-log-prior has a corner at the origin that the quadratic RSS cannot always pull the optimum past - the coordinate can stick at exactly zero. A Gaussian prior is smooth, so it shrinks but never zeroes (ELASTIC NET combines both, a Gaussian + Laplace prior mixture).

Shrinkage is Bayesian, and it is not bias - it is estimation risk control. The posterior mean under a Gaussian prior is - the same as ridge MAP because the posterior is symmetric. The estimator trades a little bias for a large variance reduction; this is the James–Stein phenomenon, and the hierarchical version (“shrink toward the group mean”, §06) is its multi-level generalization.

λ from Bayes, not from hand-tuning. If and are unknown, the empirical-Bayes choice maximizes the marginal likelihood ; cross-validation is a cheap practical proxy. This is why “tune by CV” is not ad-hoc - it approximates a hierarchical Bayes fit of the prior scale.


3. Computational Implementation - the same data under three priors

Fit OLS, ridge (MAP with a Gaussian prior), and lasso (MAP with a Laplace prior) to one fixed dataset with only 3 true non-zero coefficients out of 10. Watch ridge shrink without zeroing and lasso zero the irrelevant ones exactly. Stdlib only.

Read the three coefficient vectors together. OLS spreads small non-zero noise over all 10 coefficients. Ridge shrinks every coefficient a little (the true ones from and , the irrelevant ones toward 0) but keeps them all non-zero - a smooth Gaussian prior cannot zero anything. Lasso keeps 7 of 10 coefficients exactly zero - the corner in is what produces selection. The true non-zeros survive (), the rest vanish.


4. Failure Modes & First-Principles Breakdowns

  1. “λ is just a hyperparameter.” It is - a ratio of physical scales. If you rescale your predictors, you change the effective prior and the fit. Standardize features before penalizing, or the prior is silently non-uniform across coefficients (a constant prior on a coefficient multiplying a large-scale feature is a very different prior).
  2. MAP is not the Bayesian estimate in a high-dimensional or non-log-concave model. Ridge MAP = posterior mean because the posterior is Gaussian; the lasso MAP is not the posterior mean of the Bayesian lasso (which has no exact zeros) - it is a mode of a non-Gaussian posterior. Reporting lasso coefficients as “the posterior” conflates a mode with a distribution, and the credible intervals are not the usual ones.
  3. Bayes-optimal ≠ frequentist-optimal. The ridge estimator is deliberately biased; under squared error it beats OLS only when the prior (or the choice of ) is right. Choosing by the same test you report on leaks information. Use nested CV / a held-out set.
  4. Different priors for different features are mandatory when scales differ. A single imposes the same prior precision on all coefficients. If some features are measured in different units (or are dummies), the induced prior differs wildly. Elastic net / group lasso / weighted priors exist for this.
  5. The Gaussian prior is not a sparsity prior, and the Laplace prior is not a robustness prior to outliers. Confusing “Gaussian data noise” (which gives the loss) with the prior on (which gives the penalty) is the standard confusion - ridge does not mean “robust to outliers”; it means “coefficients are believed small”.

5. References

  • Hastie, Tibshirani & Friedman, The Elements of Statistical Learning (2nd ed.)
  • Gelman et al., Bayesian Data Analysis (3rd ed.)
  • Hoff, A First Course in Bayesian Statistical Methods
  • McElreath, Statistical Rethinking (2nd ed.)
  • Tsay, Analysis of Financial Time Series

6. Connected Graph Bridges