Bayesian View on Regularization
Understanding ridge and lasso regularization through Bayesian priors and maximum a posteriori estimation.
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:
where
- is the regression loss function, often as a negative log-likelihood of the underlying distribution of the error terms.
- is the regularization penalty.
- is a parameter that controls how much the regularization penalty should be applied. Stronger regularisation usually increases bias but reduces variance. It discourages overfitting by preventing the weights vector from being too large.
The optimal weights in regularised regression, , is given by:
Lasso () and Ridge ()
Two common regularization types are Lasso, or and Ridge, or regularization.
For a weight vector :
- / ridge regularization penalises the weight vector by the square of its norm, so large coefficients are pulled back strongly and coefficients shrink smoothly.
- / lasso regularization penalises the weight vector by its norm. Small coefficients are favoured but not to the extent as ridge regularization. However, Lasso regularization is able to produce sparse models by setting weights of weak features to exactly zero.
- Elastic net combines both penalties.
Statistical Interpretation
The choice of and regularization may seem arbitrary. To penalise large weights even more strongly, why not use the cube of the norm, instead? Or how about something like ?
As it turns out, statistics provides a good reason for why , and especially 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 , we want a weight vector such that is maximised:
This is the same as minimising the negative log-likelihood. Thus,
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
where error term is assumed to follow the normal distribution. Thus, given the independent variables , the dependent variable is also assumed to be normally distributed:
With data points, the likelihood function would thus be:
And the negative log-likelihood gives:
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 ) (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 and regularization terms are chosen.
To maximise the posterior, we can use Bayes’ Theorem,
The prior probability represents what we knew about initially, before the data is observed. Taking logs,
Therefore, maximising is the equivalent of minimising . Thus,
The regularization term of thus emerges as . How Ridge and Lasso derive their respective complexity penalty depends on the prior distribution of . The prior distribution of 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 follow independent normal distributions with mean 0, that is , then
where is a constant. By comparing this to , we can see that it results in an penalty with
As the normality assumption is often used, ridge regression becomes a natural choice.
Laplacian Prior
If we instead assume that the values of follow independent Laplace distributions with mean 0, that is , then
where is a constant. By comparing this to , we can see that it results in an penalty with .
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 are independent of the target ), 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, and 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.