# Regularization (mathematics)

(Redirected from Regularization (machine learning))
The green and blue functions both incur zero loss on the given data points. A learned model can be induced to prefer the green function, which may generalize better to more points drawn from the underlying unknown distribution, by adjusting ${\displaystyle \lambda }$, the weight of the regularization term.

In mathematics, statistics, and computer science, particularly in the fields of machine learning and inverse problems, regularization is a process of introducing additional information in order to solve an ill-posed problem or to prevent overfitting[citation needed].

## Introduction

In general, regularization is a technique that applies to objective functions in ill-posed problems formulated as optimization problems.

## Use of regularization in classification

One particular use of regularization is in the field of classification. Empirical learning of classifiers (learning from a finite data set) is always an underdetermined problem, because in general we are trying to infer a function of any ${\displaystyle x}$ given only some examples ${\displaystyle x_{1},x_{2},...x_{n}}$.

A regularization term (or regularizer) ${\displaystyle R(f)}$ is added to a loss function:

${\displaystyle \min _{f}\sum _{i=1}^{n}V(f(x_{i}),y_{i})+\lambda R(f)}$

where ${\displaystyle V}$ is an underlying loss function that describes the cost of predicting ${\displaystyle f(x)}$ when the label is ${\displaystyle y}$, such as the square loss or hinge loss; and ${\displaystyle \lambda }$ is a parameter which controls the importance of the regularization term. ${\displaystyle R(f)}$ is typically chosen to impose a penalty on the complexity of ${\displaystyle f}$. Concrete notions of complexity used include restrictions for smoothness and bounds on the vector space norm.[1][page needed]

A theoretical justification for regularization is that it attempts to impose Occam's razor on the solution, as depicted in the figure. From a Bayesian point of view, many regularization techniques correspond to imposing certain prior distributions on model parameters.

Regularization can be used to learn simpler models, induce models to be sparse, introduce group structure into the learning problem, and more.

The same idea arose in many fields of science. For example, the least-squares method can be viewed as a very simple form of regularization[citation needed]. A simple form of regularization applied to integral equations, generally termed Tikhonov regularization after Andrey Nikolayevich Tikhonov, is essentially a trade-off between fitting the data and reducing a norm of the solution. More recently, non-linear regularization methods, including total variation regularization, have become popular.

### Generalization

Regularization can be motivated as a technique to improve the generalizability of a learned model.

The goal of this learning problem is to find a function that fits or predicts the outcome (label) that minimizes the expected error over all possible inputs and labels. The expected error of a function ${\displaystyle f_{n}}$ is:

${\displaystyle I[f_{n}]=\int _{X\times Y}V(f_{n}(x),y)\rho (x,y)\,dx\,dy}$

Typically in learning problems, only a subset of input data and labels are available, measured with some noise. Therefore, the expected error is unmeasurable, and the best surrogate available is the empirical error over the ${\displaystyle N}$ available samples:

${\displaystyle I_{S}[f_{n}]={\frac {1}{n}}\sum _{i=1}^{N}V(f_{n}({\hat {x}}_{i}),{\hat {y}}_{i})}$

Without bounds on the complexity of the function space (formally, the reproducing kernel Hilbert space) available, a model will be learned that incurs zero loss on the surrogate empirical error. If measurements (e.g. of ${\displaystyle x_{i}}$) were made with noise, this model may suffer from overfitting and display poor expected error. Regularization introduces a penalty for exploring certain regions of the function space used to build the model, which can improve generalization.

## Tikhonov regularization

When learning a linear function ${\displaystyle f}$, characterized by an unknown vector ${\displaystyle w}$ such that ${\displaystyle f(x)=w\cdot x}$, the ${\displaystyle L_{2}}$-norm loss corresponds to[clarification needed] Tikhonov regularization. This is one of the most common forms of regularization, is also known as ridge regression, and is expressed as:

${\displaystyle \min _{w}\sum _{i=1}^{n}V({\hat {x}}_{i}\cdot w,{\hat {y}}_{i})+\lambda \|w\|_{2}^{2}}$

In the case of a general function, we take the norm of the function in its reproducing kernel Hilbert space:

${\displaystyle \min _{f}\sum _{i=1}^{n}V(f({\hat {x}}_{i}),{\hat {y}}_{i})+\lambda \|f\|_{\mathcal {H}}^{2}}$

As the ${\displaystyle L_{2}}$ norm is differentiable, learning problems using Tikhonov regularization can be solved by gradient descent.

### Tikhonov-regularized least squares

The learning problem with the least squares loss function and Tikhonov regularization can be solved analytically. Written in matrix form, the optimal ${\displaystyle w}$ will be the one for which the gradient of the loss function with respect to ${\displaystyle w}$ is 0.

${\displaystyle \min _{w}{\frac {1}{n}}({\hat {X}}w-Y)^{T}({\hat {X}}w-Y)+\lambda \|w\|_{2}^{2}}$
${\displaystyle \nabla _{w}={\frac {2}{n}}{\hat {X}}^{T}({\hat {X}}w-Y)+2\lambda w}$       ${\displaystyle \leftarrow }$This is the first-order condition for this optimization problem
${\displaystyle 0={\hat {X}}^{T}({\hat {X}}w-Y)+n\lambda w}$
${\displaystyle w=({\hat {X}}^{T}{\hat {X}}+\lambda nI)^{-1}({\hat {X}}^{T}Y)}$

By construction of the optimization problem, other values of ${\displaystyle w}$ would give larger values for the loss function. This could be verified by examining the second derivative ${\displaystyle \nabla _{ww}}$.

During training, this algorithm takes ${\displaystyle O(d^{3}+nd^{2})}$ time. The terms correspond to the matrix inversion and calculating ${\displaystyle X^{T}X}$, respectively. Testing takes ${\displaystyle O(nd)}$ time.

## Early stopping

Early stopping can be viewed as regularization in time. Intuitively, a training procedure like gradient descent will tend to learn more and more complex functions as the number of iterations increases. By regularizing on time, the complexity of the model can be controlled, improving generalization.

In practice, early stopping is implemented by training on a training set and measuring accuracy on a statistically independent validation set. The model is trained until performance on the validation set no longer improves. The model is then tested on a testing set.

### Theoretical motivation in least squares

Consider the finite approximation of Neumann series for an invertible matrix ${\displaystyle A}$ where ${\displaystyle \|I-A\|<1}$:

${\displaystyle \sum _{i=0}^{T-1}(I-A)^{i}\approx A^{-1}}$

This can be used to approximate the analytical solution of unregularized least squares, if ${\displaystyle \gamma }$ is introduced to ensure the norm is less than one.

${\displaystyle w_{T}={\frac {\gamma }{n}}\sum _{i=0}^{T-1}(I-{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {X}})^{i}{\hat {X}}^{T}{\hat {Y}}}$

The exact solution to the unregularized least squares learning problem will minimize the empirical error, but may fail to generalize and minimize the expected error. By limiting ${\displaystyle T}$, the only free parameter in the algorithm above, the problem is regularized on time which may improve its generalization.

The algorithm above is equivalent to restricting the number of gradient descent iterations for the empirical risk

${\displaystyle I_{s}[w]={\frac {1}{2n}}\|{\hat {X}}w-{\hat {Y}}\|_{\mathbb {R} ^{n}}^{2}}$

${\displaystyle w_{0}=0}$
${\displaystyle w_{t+1}=(I-{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {X}})w_{t}+{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {Y}}}$

The base case is trivial. The inductive case is proved as follows:

${\displaystyle w_{T}=(I-{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {X}}){\frac {\gamma }{n}}\sum _{i=0}^{T-2}(I-{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {X}})^{i}{\hat {X}}^{T}{\hat {Y}}+{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {Y}}}$
${\displaystyle w_{T}={\frac {\gamma }{n}}\sum _{i=1}^{T-1}(I-{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {X}})^{i}{\hat {X}}^{T}{\hat {Y}}+{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {Y}}}$
${\displaystyle w_{T}={\frac {\gamma }{n}}\sum _{i=0}^{T-1}(I-{\frac {\gamma }{n}}{\hat {X}}^{T}{\hat {X}})^{i}{\hat {X}}^{T}{\hat {Y}}}$

## Regularizers for sparsity

Assume that a dictionary ${\displaystyle \phi _{j}}$ with dimension ${\displaystyle p}$ is given such that a function in the function space can be expressed as:

${\displaystyle f(x)=\sum _{j=1}^{p}\phi _{j}(x)w_{j}}$
A comparison between the L1 ball and the L2 ball in two dimensions gives an intuition on how L1 regularization achieves sparsity.

Enforcing a sparsity constraint on ${\displaystyle w}$ can lead to simpler and more interpretable models. This is useful in many real-life applications such as computational biology. An example is developing a simple predictive test for a disease in order to minimize the cost of performing medical tests while maximizing predictive power.

A sensible sparsity constraint is the ${\displaystyle L_{0}}$ norm ${\displaystyle \|w\|_{0}}$, defined as the number of non-zero elements in ${\displaystyle w}$. Solving a ${\displaystyle L_{0}}$ regularized learning problem, however, has been demonstrated to be NP-hard.[2]

The ${\displaystyle L_{1}}$ norm can be used to approximate the optimal ${\displaystyle L_{0}}$ norm via convex relaxation. It can be shown that the ${\displaystyle L_{1}}$ norm induces sparsity. In the case of least squares, this problem is known as LASSO in statistics and basis pursuit in signal processing.

${\displaystyle \min _{w\in \mathbb {R} ^{p}}{\frac {1}{n}}\|{\hat {X}}w-{\hat {Y}}\|^{2}+\lambda \|w\|_{1}}$
Elastic net regularization

${\displaystyle L_{1}}$ regularization can occasionally produce non-unique solutions. A simple example is provided in the figure when the space of possible solutions lies on a 45 degree line. This can be problematic for certain applications, and is overcome by combining ${\displaystyle L_{1}}$ with ${\displaystyle L_{2}}$ regularization in elastic net regularization, which takes the following form:

${\displaystyle \min _{w\in \mathbb {R} ^{p}}{\frac {1}{n}}\|{\hat {X}}w-{\hat {Y}}\|^{2}+\lambda (\alpha \|w\|_{1}+(1-\alpha )\|w\|_{2}^{2}),\alpha \in [0,1]}$

Elastic net regularization tends to have a grouping effect, where correlated input features are assigned equal weights.

Elastic net regularization is commonly used in practice and is implemented in many machine learning libraries.

### Proximal methods

While the ${\displaystyle L_{1}}$ norm does not result in an NP-hard problem, it should be noted that the ${\displaystyle L_{1}}$ norm is convex but is not strictly diffentiable due to the kink at x = 0. Subgradient methods which rely on the subderivative can be used to solve ${\displaystyle L_{1}}$ regularized learning problems. However, faster convergence can be achieved through proximal methods.

For a problem ${\displaystyle \min _{w\in H}F(w)+R(w)}$ such that ${\displaystyle F}$ is convex, continuous, differentiable, with Lipschitz continuous gradient (such as the least squares loss function), and ${\displaystyle R}$ is convex, continuous, and proper, then the proximal method to solve the problem is as follows. First define the proximal operator

${\displaystyle \operatorname {prox} _{R}(v)=\operatorname {argmin} \limits _{w\in \mathbb {R} ^{D}}\{R(w)+{\frac {1}{2}}\|w-v\|^{2}\},}$

and then iterate

${\displaystyle w_{k+1}=\operatorname {prox} \limits _{\gamma ,R}(w_{k}-\gamma \nabla F(w_{k}))}$

The proximal method iteratively performs gradient descent and then projects the result back into the space permitted by ${\displaystyle R}$.

When ${\displaystyle R}$ is the ${\displaystyle L_{1}}$ regularizer, the proximal operator is equivalent to the soft-thresholding operator,

${\displaystyle S_{\lambda }(v)f(n)={\begin{cases}v_{i}-\lambda ,&{\text{if }}v_{i}>\lambda \\0,&{\text{if }}v_{i}\in [-\lambda ,\lambda ]\\v_{i}+\lambda ,&{\text{if }}v_{i}<-\lambda \end{cases}}}$

This allows for efficient computation.

### Group sparsity without overlaps

Groups of features can be regularized by a sparsity constraint, which can be useful for expressing certain prior knowledge into an optimization problem.

In the case of a linear model with non-overlapping known groups, a regularizer can be defined:

${\displaystyle R(w)=\sum _{g=1}^{G}\|w_{g}\|_{g},}$ where ${\displaystyle \|w_{g}\|_{g}={\sqrt {\sum _{j=1}^{|G_{g}|}(w_{g}^{j})^{2}}}}$

This can be viewed as inducing a regularizer over the ${\displaystyle L_{2}}$ norm over members of each group followed by an ${\displaystyle L_{1}}$ norm over groups.

This can be solved by the proximal method, where the proximal operator is a block-wise soft-thresholding function:

${\displaystyle (\operatorname {prox} \limits _{\lambda ,R,g}(w_{g}))^{j}={\begin{cases}(w_{g}^{j}-\lambda {\frac {w_{g}^{j}}{\|w_{g}\|_{g}}}),&{\text{if }}\|w_{g}\|_{g}>\lambda \\0&{\text{if }}\|w_{g}\|_{g}\in [-\lambda ,\lambda ]\\(w_{g}^{j}+\lambda {\frac {w_{g}^{j}}{\|w_{g}\|_{g}}}),&{\text{if }}\|w_{g}\|_{g}<-\lambda \end{cases}}}$

### Group sparsity with overlaps

The algorithm described for group sparsity without overlaps can be applied to the case where groups do overlap, in certain situations. It should be noted that this will likely result in some groups with all zero elements, and other groups with some non-zero and some zero elements.

If it is desired to preserve the group structure, a new regularizer can be defined:

${\displaystyle R(w)=\inf \left\{\sum _{g=1}^{G}\|w_{g}\|_{g}:w=\sum _{g=1}^{G}{\bar {w}}_{g}\right\}}$

For each ${\displaystyle w_{g}}$, ${\displaystyle {\bar {w}}_{g}}$ is defined as the vector such that the restriction of ${\displaystyle {\bar {w}}_{g}}$ to the group ${\displaystyle g}$ equals ${\displaystyle w_{g}}$ and all other entries of ${\displaystyle {\bar {w}}_{g}}$ are zero. The regularizer finds the optimal disintegration of ${\displaystyle w}$ into parts. It can be viewed as duplicating all elements that exist in multiple groups. Learning problems with this regularizer can also be solved with the proximal method with a complication. The proximal operator cannot be computed in closed form, but can be effectively solved iteratively, inducing an inner iteration within the proximal method iteration.

## Regularizers for semi-supervised learning

When labels are more expensive to gather than input examples, semi-supervised learning can be useful. Regularizers have been designed to guide learning algorithms to learn models that respect the structure of unsupervised training samples. If a symmetric weight matrix ${\displaystyle W}$ is given, a regularizer can be defined:

${\displaystyle R(f)=\sum _{i,j}w_{ij}(f(x_{i})-f(x_{j}))^{2}}$

If ${\displaystyle W_{ij}}$ encodes the result of some distance metric for points ${\displaystyle x_{i}}$ and ${\displaystyle x_{j}}$, it is desirable that ${\displaystyle f(x_{i})\approx f(x_{j})}$. This regularizer captures this intuition, and is equivalent to:

${\displaystyle R(f)={\bar {f}}^{T}L{\bar {f}}}$ where ${\displaystyle L=D-W}$ is the Laplacian matrix of the graph induced by ${\displaystyle W}$.

The optimization problem ${\displaystyle \min _{f\in \mathbb {R} ^{m}}R(f),m=u+l}$ can be solved analytically if the constraint ${\displaystyle f(x_{i})=y_{i}}$ is applied for all supervised samples. The labeled part of the vector ${\displaystyle f}$ is therefore obvious. The unlabeled part of ${\displaystyle f}$ is solved for by:

${\displaystyle \min _{f_{u}\in \mathbb {R} ^{u}}f^{T}Lf=\min _{f_{u}\in \mathbb {R} ^{u}}\{f_{u}^{T}L_{uu}f_{u}+f_{l}^{T}L_{lu}f_{u}+f_{u}^{T}L_{ul}f_{l}\}}$
${\displaystyle \nabla _{f_{u}}=2L_{uu}f_{u}+2L_{ul}Y}$
${\displaystyle f_{u}=L_{uu}^{\dagger }(L_{ul}Y)}$

Note that the pseudo-inverse can be taken because ${\displaystyle L_{ul}}$ has the same range as ${\displaystyle L_{uu}}$.

In the case of multitask learning, ${\displaystyle T}$ problems are considered simultaneously, each related in some way. The goal is to learn ${\displaystyle T}$ functions, ideally borrowing strength from the relatedness of tasks, that have predictive power. This is equivalent to learning the matrix ${\displaystyle W:T\times D}$ .

### Sparse regularizer on columns

${\displaystyle R(w)=\sum _{i=1}^{D}\|W\|_{2,1}}$

This regularizer defines an L2 norm on each column and an L1 norm over all columns. It can be solved by proximal methods.

### Nuclear norm regularization

${\displaystyle R(w)=\|\sigma (W)\|_{1}}$ where ${\displaystyle \sigma (W)}$ is the eigenvalues in the singular value decomposition of ${\displaystyle W}$.

### Mean-constrained regularization

${\displaystyle R(f_{1}\cdots f_{T})=\sum _{t=1}^{T}\|f_{t}-{\frac {1}{T}}\sum _{s=1}^{T}f_{s}\|_{H_{k}}^{2}}$

This regularizer constrains the functions learned for each task to be similar to the overall average of the functions across all tasks. This is useful for expressing prior information that each task is expected to share similarities with each other task. An example is predicting blood iron levels measured at different times of the day, where each task represents a different person.

### Clustered mean-constrained regularization

${\displaystyle R(f_{1}\cdots f_{T})=\sum _{r=1}^{C}\sum _{t\in I(r)}\|f_{t}-{\frac {1}{I(r)}}\sum _{s\in I(r)}f_{s}\|_{H_{k}}^{2}}$ where ${\displaystyle I(r)}$ is a cluster of tasks.

This regularizer is similar to the mean-constrained regularizer, but instead enforces similarity between tasks within the same cluster. This can capture more complex prior information. This technique has been used to predict Netflix recommendations. A cluster would correspond to a group of people who share similar preferences in movies.

### Graph-based similarity

More general than above, similarity between tasks can be defined by a function. The regularizer encourages the model to learn similar functions for similar tasks.

${\displaystyle R(f_{1}\cdots f_{T})=\sum _{t,s=1,t\neq s}^{T}\|f_{t}-f_{s}\|^{2}M_{ts}}$ for a given symmetric similarity matrix ${\displaystyle M}$.

## Other uses of regularization in statistics and machine learning

Bayesian learning methods make use of a prior probability that (usually) gives lower probability to more complex models. Well-known model selection techniques include the Akaike information criterion (AIC), minimum description length (MDL), and the Bayesian information criterion (BIC). Alternative methods of controlling overfitting not involving regularization include cross-validation.

Examples of applications of different methods of regularization to the linear model are:

Model Fit measure Entropy measure[1][3]
AIC/BIC ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \|\beta \|_{0}}$
Ridge regression[4] ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \|\beta \|_{2}}$
Lasso[5] ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \|\beta \|_{1}}$
Basis pursuit denoising ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \lambda \|\beta \|_{1}}$
Rudin–Osher–Fatemi model (TV) ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \lambda \|\nabla \beta \|_{1}}$
Potts model ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \lambda \|\nabla \beta \|_{0}}$
RLAD[6] ${\displaystyle \|Y-X\beta \|_{1}}$ ${\displaystyle \|\beta \|_{1}}$
Dantzig Selector[7] ${\displaystyle \|X^{\top }(Y-X\beta )\|_{\infty }}$ ${\displaystyle \|\beta \|_{1}}$
SLOPE[8] ${\displaystyle \|Y-X\beta \|_{2}}$ ${\displaystyle \sum _{i=1}^{p}\lambda _{i}|\beta |_{(i)}}$