Skip to content
datarekha
Machine Learning Hard Asked at GoogleAsked at DeepMindAsked at Two Sigma

What is the Bayesian interpretation of Ridge regression, and what prior does it correspond to?

The short answer

Ridge regression is maximum a posteriori estimation for a linear model with Gaussian observation noise and a zero-mean Gaussian prior on the coefficients. The regularization strength is the noise variance divided by the prior variance, subject to the scaling convention used in the Ridge objective.

How to think about it

Short answer

Ridge regression is maximum a posteriori estimation, or MAP estimation, for a linear model whose coefficients have a zero-mean Gaussian prior. Under the common objective ||y - Xβ||² + λ||β||², the regularization strength is λ = σ² / τ²: observation noise variance divided by coefficient-prior variance.

Why this is true

Suppose y is the target vector, X is the feature matrix, and β is the vector of regression coefficients. The Bayesian model makes two assumptions:

  • The observed targets are noisy versions of : y | X, β ~ N(Xβ, σ²I).
  • Before seeing the data, each coefficient is believed to come from N(0, τ²), independently of the others.

The second assumption is a zero-mean isotropic Gaussian prior. “Zero-mean” says that, before seeing evidence, positive and negative effects are equally plausible and an effect near zero is most plausible. “Isotropic” says every coefficient gets the same prior variance, τ².

Bayes’ theorem combines the likelihood, which measures how well the model explains the observed data, with the prior, which expresses what coefficient values seemed plausible beforehand:

p(β | X, y) ∝ p(y | X, β)p(β)

MAP estimation chooses the coefficient vector with the highest posterior probability. Taking the negative logarithm turns multiplication into addition. Ignoring constants that do not depend on β, the negative log-posterior is:

(1 / (2σ²))||y - Xβ||² + (1 / (2τ²))||β||²

The first term is the data-fit term. It is expensive when predictions miss the targets. The second term is the prior penalty. It is expensive when coefficients move far from zero.

Multiply the whole expression by 2σ². Multiplying an objective by a positive constant does not change its minimizer:

||y - Xβ||² + (σ² / τ²)||β||²

That is the Ridge objective:

minimize ||y - Xβ||² + λ||β||²

So, with this exact convention:

λ = σ² / τ²

The mechanism is worth saying in words. A noisy target, meaning large σ², makes extreme coefficients less trustworthy, so the Bayesian model imposes stronger shrinkage. A broad prior, meaning large τ², says large coefficients are plausible, so the penalty becomes weaker.

For a model without an intercept, the solution can be written as:

β_MAP = (XᵀX + λI)⁻¹Xᵀy

The λI term adds a positive amount to the diagonal of XᵀX. That makes the system better behaved when features are correlated or when there are more features than observations. The Bayesian interpretation gives that numerical trick a meaning: the prior supplies information in directions where the data alone is weak.

One detail matters in interviews. Not every library writes the objective with the same factors. If the objective is written as (1/2)||y - Xβ||² + λ||β||², the matching coefficient is σ² / (2τ²). If it is written as (1/(2n))||y - Xβ||² + λ||β||², the coefficient is σ² / (2nτ²). The underlying relationship is unchanged; only the bookkeeping differs. Always match the objective’s scaling before quoting a numerical value for λ.

A concrete example

Take a small house-price model. Let the target be measured in units of ten thousand dollars, and let β represent the effect of one unit of a transformed square-footage feature. We will use one feature so the arithmetic is visible.

Suppose the data gives:

  • xᵀx = 4
  • The ordinary least-squares coefficient is β_OLS = 2.4
  • The observation-noise variance is σ² = 4
  • The prior variance is τ² = 9

The prior standard deviation is therefore 3, or thirty thousand dollars in the target’s units. It says that an effect near zero is more plausible than a very large effect, but it does not say a large effect is impossible.

Under the Ridge objective RSS + λβ²:

λ = σ² / τ² = 4 / 9 ≈ 0.444

Because β_OLS = (xᵀy)/(xᵀx), we know that xᵀy = 4 × 2.4 = 9.6. The Ridge estimate is:

β_Ridge = (xᵀy) / (xᵀx + λ)

β_Ridge = 9.6 / (4 + 4/9) = 2.16

The coefficient moved from 2.4 to 2.16. That is a ten percent shrinkage toward zero. The model did not decide that square footage has no effect. It decided that, given the noise level and the prior belief, a slightly smaller effect is the more probable explanation.

Now make the prior much tighter: let τ² = 1. The same data and noise give λ = 4, so:

β_Ridge = 9.6 / (4 + 4) = 1.2

The estimate is now cut in half. Nothing about the observations changed. Only the prior changed. This is exactly what regularization is doing, whether or not the practitioner describes it in Bayesian language.

What the Gaussian prior does not mean

A Gaussian prior does not force coefficients to be zero. It makes values near zero more probable and progressively penalizes larger values. Its density is smooth at zero, so the optimization has no sharp corner that would pin a coefficient exactly to zero.

That is why Ridge usually keeps every feature in the model, although it may make many coefficients very small.

EstimatorPenaltyBayesian priorTypical result
RidgeL2, ||β||²Zero-mean GaussianShrinks coefficients smoothly
LassoL1, ||β||₁Laplace, or double-exponentialCan produce exact zeros
OLSNo penaltyFlat improper prior, in the limiting viewUses only the likelihood

The Laplace prior has a sharper peak at zero than the Gaussian prior. Its negative log-prior is proportional to |β|, which creates the kink responsible for exact zeros in Lasso solutions. Ridge is usually the better choice when many features may have small effects, or when correlated features should share predictive responsibility. Lasso is more attractive when a compact feature set is itself a requirement.

There is also a practical trap: the prior is placed on coefficient values, so feature units matter. If square footage is entered in square feet rather than thousands of square feet, the corresponding coefficient changes by a factor of one thousand. Applying the same penalty to both versions does not express the same prior belief. Standardizing features before Ridge makes a common prior scale more defensible. An alternative is to specify different prior variances for features measured in different units.

The usual linear-model intercept is not penalized. Shrinking the intercept can distort the overall baseline, especially when features and targets have not been centered. When someone says “Ridge shrinks all coefficients to zero,” the technically correct version is “Ridge shrinks the penalized slope coefficients toward zero.” The intercept is commonly left alone.

The senior-level nuance

Ridge is MAP, not automatically full Bayesian inference. A standard Ridge fit returns one best coefficient vector, often with λ selected by cross-validation. It does not, by itself, return a posterior distribution or principled uncertainty intervals.

With fixed σ² and τ², the posterior in this Gaussian model is itself Gaussian. Its mean and mode are the same, so the Ridge estimate is both the MAP estimate and the posterior mean under those fixed hyperparameters. But Ridge software normally discards the rest of that posterior. To quantify uncertainty, you need the posterior covariance, a Bayesian regression implementation, or another appropriate uncertainty method.

sklearn.linear_model.BayesianRidge is a useful distinction:

from sklearn.linear_model import BayesianRidge

model = BayesianRidge()
model.fit(X_train, y_train)

mean, std = model.predict(X_test, return_std=True)
print(model.alpha_)
print(model.lambda_)

In BayesianRidge, alpha_ is the fitted noise precision, approximately 1 / σ², and lambda_ is the fitted coefficient precision, approximately 1 / τ². Their ratio corresponds to the Ridge penalty under the matching objective because:

lambda_ / alpha_ = (1 / τ²) / (1 / σ²) = σ² / τ²

The important qualification is that BayesianRidge estimates these hyperparameters by maximizing the marginal likelihood, often called an empirical-Bayes procedure. It provides a coefficient posterior conditional on the fitted hyperparameters; it does not fully integrate over every possible value of those hyperparameters. That is more Bayesian information than ordinary Ridge, but it is not the same as a fully specified hierarchical Bayesian analysis.

The isotropic prior is another modeling choice, not a law of nature. If domain knowledge says coefficient β₁ should be more variable than β₂, use different prior variances. If coefficients are expected to move together, use a covariance matrix rather than τ²I. A general Gaussian prior N(m, Σ) produces a penalty based on:

(β - m)ᵀΣ⁻¹(β - m)

That lets the prior have a nonzero center and encode relationships among coefficients. In production, this can matter more than the choice between two familiar regularizers.

Finally, Ridge trades bias for variance. It biases coefficients toward zero, which can hurt if the true effects are large and the data is plentiful. It often improves prediction when features are collinear because small changes in the data can otherwise cause large changes in individual OLS coefficients. If the goal is unbiased coefficient estimation, causal interpretation, or exact variable selection, Ridge should not be applied on autopilot. Cross-validation can choose a useful predictive penalty, but it cannot repair a badly chosen feature scale or a prior that contradicts the problem.

What they’ll ask next

“Why does Ridge help with multicollinearity?”

When two columns of X are nearly duplicates, XᵀX has a very small eigenvalue, so OLS can produce large, unstable coefficients with opposite signs. Ridge adds λI, lifting those small eigenvalues away from zero. The resulting estimates are biased but much less sensitive to sampling noise. It stabilizes the combined prediction more reliably than it identifies which duplicate feature deserves the credit.

“Is Bayesian Ridge the same as Ridge?”

With fixed noise and prior variances, and with matching objective scaling, their MAP coefficient estimates are the same. BayesianRidge additionally estimates the noise and weight precisions and can provide posterior or predictive uncertainty. It is therefore related to Ridge, not simply a different name for cross-validated Ridge.

“What happens when λ goes to zero?”

For a full-rank design matrix, the Ridge solution approaches OLS because the prior becomes effectively flat. If the design is rank-deficient, OLS may have many solutions; Ridge approaches the minimum-Euclidean-norm least-squares solution instead. As λ becomes very large, the penalized slopes approach zero, while an unpenalized intercept does not necessarily do so.

Say this in the interview

“Ridge is the MAP estimate for Gaussian linear regression with a zero-mean Gaussian coefficient prior; under the objective RSS + λ||β||², λ equals the noise variance divided by the prior variance, so stronger shrinkage means either noisier observations or a tighter belief that effects are small.”

Learn it properly L1, L2, Elastic Net

Keep practising

All Machine Learning questions

Explore further