Bayesian View on Regularization

Understanding ridge and lasso regularization through Bayesian priors and maximum a posteriori estimation.

beginner classical ml supervised-learningregressionstatistics
regularizationbayesian-inferenceridgelassomap-estimation

Author @CJBuzz Updated 2026-10-19

Regularization

Regularization is a technique in machine learning used to prevent overfitting. In regression, this is done by adding penalty term to the loss function that makes large weights costly. Thus, the combined loss function is given by:

L(β;X,y)+λR(β)L(\beta;X,\mathbf y)+\lambda R(\beta)

where

The optimal weights in regularised regression, β^\hat \beta, is given by:

β^=arg⁡min⁡β[L(β;X,y)+λR(β)].\hat\beta =\arg\min_\beta \left[ L(\beta;X,\mathbf y) +\lambda R(\beta) \right].

Lasso (L1L_1) and Ridge (L2L_2)

Two common regularization types are Lasso, or L1L_1 and Ridge, or L2L_2 regularization.

For a weight vector β\beta:

RL2(β)=∥β∥22=∑jβj2,RL1(β)=∥β∥1=∑j∣βj∣.R_{L_2}(\beta)=\lVert \beta\rVert_2^2=\sum_j\beta_j^2, \qquad R_{L_1}(\beta)=\lVert \beta\rVert_1=\sum_j|\beta_j|.

Statistical Interpretation

The choice of L1L_1 and L2L_2 regularization may seem arbitrary. To penalise large weights even more strongly, why not use the cube of the L3L_3 norm, ∥β∥33\lVert \beta\rVert_3^3 instead? Or how about something like ∑j∣βj∣1.5\sum_j |\beta_j|^{1.5}?

As it turns out, statistics provides a good reason for why L1L_1, and especially L2L_2 regularization are often considered the normal choice. To understand why, it helps to view regression some a statistical standpoint as well.

Regression as the Maximisation of Likelihood

Regression can be viewed as the maximisation of likelihood. That is, for observed data y\mathbf y, we want a weight vector β\beta such that p(y∣β)p(\mathbf y \mid \beta) is maximised:

β^=arg⁡max⁡βp(y∣β).\hat\beta = \arg\max_\beta p(\mathbf y \mid \beta).

This is the same as minimising the negative log-likelihood. Thus,

β^=arg⁡min⁡βL(β;X,y).\hat\beta = \arg\min_\beta L(\beta; X,\mathbf y).
Demonstration with Ordinary Least Squares

This view is useful in demonstrating why Mean Squared Error is a common loss function for linear regression. In linear regression, we have

yi=xiTβ+εi,y_i=\mathbf x_i^T\beta+\varepsilon_i,

where error term εi∼N(0,σ2)\varepsilon_i\sim \mathcal N(0, \sigma^2) is assumed to follow the normal distribution. Thus, given the independent variables xi\mathbf x_i, the dependent variable yiy_i is also assumed to be normally distributed:

yi∣xi∼N(xiTβ,σ2).y_i \mid \mathbf x_i\sim \mathcal N(\mathbf x_i^T\beta , \sigma^2).

With nn data points, the likelihood function would thus be:

∏i=1nf(yi∣xiT;β,σ2)=∏i=1n[12πσexp⁡(−(yi−xiTβ)22σ2)].\prod^n_{i=1}f(y_i\mid \mathbf x_i^T;\beta,\sigma^2)= \prod^n_{i=1} \left[ \frac 1{\sqrt{2\pi}\sigma}\exp\left(-\frac{(y_i-\mathbf x_i^T\beta)^2}{2\sigma^2}\right)\right].

And the negative log-likelihood gives:

L(β;X,y)=nlog⁡2πσ+12σ2∑i=1n(yi−xiTβ)2.L(\beta; X,\mathbf y)= n\log \sqrt{2\pi}\sigma +\frac 1{2\sigma^2} \sum^n_{i=1}(y_i-x_i^T\beta)^2.

As can be seen, minimising the negative log-likelihood is equivalent to minimising MSE loss.

Frequentist and Bayesian Interpretations

The maximisation of likelihood (or Maximum Likelihood Estimation) is the primary concern of Frequentist Statistics. In Frequentist Statistics, data is random while parameters are fixed. The opposing paradigm is Bayesian Statistics. Bayesian Statistics takes the view that data is observed (fixed) while parameters are unknown (thus random). Here, the primary concern would be the maximisation of posterior p(β∣yp(\beta \mid \mathbf y) (or Maximum a posteriori Estimation). Bayesian Statistics can provide an understanding on the necessity of the addition of the regularization term, and why the specific L1L_1 and L2L_2 regularization terms are chosen.

To maximise the posterior, we can use Bayes’ Theorem,

p(β∣y)⏟posterior∝p(y∣β)⏟likelihood  p(β)⏟prior.\underbrace{p(\beta\mid \mathbf y)}_{\text{posterior}} \propto \underbrace{p(\mathbf y \mid\beta)}_{\text{likelihood}} \; \underbrace{p(\beta)}_{\text{prior}}.

The prior probability represents what we knew about β\beta initially, before the data is observed. Taking logs,

−log⁡p(β∣y)=−log⁡p(y∣β)−log⁡p(β)+constant.-\log p(\beta\mid \mathbf y) =-\log p(\mathbf y \mid\beta)-\log p(\beta)+\text{constant}.

Therefore, maximising p(β∣y)p(\beta\mid \mathbf y) is the equivalent of minimising −log⁡p(y∣β)−log⁡p(β)-\log p(\mathbf y \mid\beta)-\log p(\beta). Thus,

β^=arg⁡min⁡β[L(β;X,y)−log⁡p(β)].\hat\beta =\arg\min_\beta \left[ L(\beta;X,\mathbf y) -\log p(\beta) \right].

The regularization term of λR(β)\lambda R(\beta) thus emerges as log⁡p(β)\log p(\beta). How Ridge and Lasso derive their respective complexity penalty depends on the prior distribution of β\beta. The prior distribution of β\beta can be set based on our goals. To prevent overfitting, smaller weights are preferred. This preference can be encoded by setting the mean of the prior distribution to be 0 (i.e. we have prior information that the weights are not going to be very large).

Gaussian Prior

If we assume that the values of β\beta follow independent normal distributions with mean 0, that is βi∼N(0,τ2)\beta_i \sim \mathcal N(0, \tau^2), then

log⁡p(β)=−∥β∥222τ2+c\log p(\beta)= -\frac{\lVert \beta\rVert_2^2}{2\tau^2} + c

where cc is a constant. By comparing this to λR(β)\lambda R(\beta), we can see that it results in an L2L_2 penalty with λ=12τ2.\lambda = \frac 1{2\tau^2}.

As the normality assumption is often used, ridge regression becomes a natural choice.

Laplacian Prior

If we instead assume that the values of β\beta follow independent Laplace distributions with mean 0, that is βi∼L(0,b)\beta_i \sim \mathcal L(0, b), then

log⁡p(β)∝−∥β∥1b\log p(\beta)\propto-\frac{\lVert \beta\rVert_1}{b}

where cc is a constant. By comparing this to λR(β)\lambda R(\beta), we can see that it results in an L1L_1 penalty with λ=1b\lambda = \frac 1b.

In Layman Terms

The statistical interpretation of regularization can be thought of as:

Assume the expected value of weight is 0 (or that the features x\mathbf{x} are independent of the target yy), with the weights following a continuous distribution.

Given both the above assumption and the data, what is the value of the weights that that maximises the likelihood of observing the given outputs, from the given inputs?

On the Importance of Scaling

With regularization penalising large weights, input features must be on comparable scales. If not, L1L_1 and L2L_2 regularization will unfairly penalise features with a smaller range, as since they apply the cost uniformly across all features. Features with smaller range would need larger weight coefficients to have the same impact on the model’s output, and will thus be penalised more. Meanwhile, features with larger range will tend to have smaller coefficients and will be penalised less. As a result, regularization would result in models more strongly impacted by features with a larger range.

Learning Path

What should I learn before Bayesian View on Regularization?

Start with linear-regression, probability-and-bayesian-inference before studying Bayesian View on Regularization.

How does Bayesian View on Regularization connect to other AI topics?

Bayesian View on Regularization belongs to Classical ML and connects to supervised-learning, regression, statistics, regularization, bayesian-inference, ridge, lasso, map-estimation.

Further Reading

  1. Pattern Recognition and Machine Learning (Chapter 3)