When building models, data scientists and statisticians often talk about penalty, regularization and shrinkage. What do these terms mean and why are they important?

According to Wikipedia, regularization "refers to a process of introducing additional information in order to solve an ill-posed problem or to prevent overfitting. This information usually comes in the form of a penalty for complexity, such as restrictions for smoothness or bounds on the vector space norm.”

Shrinkage can be thought of as "a penalty of complexity." Why? If we set some parameters of the model to exactly zero, then the model is effectively shrunk to have lower-dimensionality and less complex. Analogously, if we use a shrinkage mechanism to zero out some of the parameters or smooth the parameters (the difference of parameters will not be very large), then we are decreasing complexity by reducing dimensions or making it more continuous.

Why do we want to use shrinkage mechanism in training data? In real life, we often encounter problems where we have less data but a lot of features in our problem. These problems become ill-posed, meaning no unique solution can be found.

In fact, without using shrinkage, we can find a lot, if not unlimited, solutions to them. And the learned model from such data sets will often over fit. It will fit the training data perfectly but it does not generalize well to the unseen data (See Figure 1).

Before we jump into this figure, let us first explain what the figure means. In Figure 1, the blue line is the true underlying model. The blue circles are noisy samples drawn from the model. We separate all samples into two groups -- training samples denoted by blue solid circles and testing samples represented by blue dotted circles. Our problem can be expressed as:

\begin{equation}\label{eq:LS}

\hat\beta =\mathrm{arg}\max_{\beta}\sum_{j=1}^{n}(y_j-\sum_{i=1}\beta_i\phi_i(x_j))^2

\end{equation}

where \(\) is the parameter that we want to learn, \(\) is the \(\)th data point and \(\) is the \(\)th predicted value in the training data set.

Assume that the red line is the regression model we learn from the training data set. It can be seen that the learned model fits the training data set perfectly, while it cannot generalize well to the data not included in the training set. There are several ways to avoid the problem of overfitting.

To remedy this problem, we could:

- Get more training examples.
- Use a simple predictor.
- Select a subsample of features.

In this blog post, we focus on the second and third ways to avoid overfitting by introducing regularization on the parameters \(\) of the model.

Three types of regularization are often used in such a regression problem:

• *\(\)* regularization (use a simpler model)

*• \(\)* regularization (select a subsample of features)

• *\(\)* regularization (both)

*\(\)* regularization, which adds a penalty of *\(\)* norm on the parameters \(\), encourages the sum of the squares of the parameters \(\) to be small. The original problem is transformed to the ridge regression, which can be expressed as

\begin{eqnarray}\label{eq:ridge}

\hat\beta = \mathrm{arg}\max_{\beta}\sum_{j=1}^{n}(y_j-\sum_{i=1}\beta_j\phi_i(x_j))^2+\lambda\sum_i\beta_i^2

\end{eqnarray}

where the shrinkage parameter \(\) need be tuned via cross-validation.

The *\(\)* regularization can be explained from a geometric perspective. As shown in Figure 2, the residual sum of squares has elliptical contours, represented by a black curve. The *\(\)* constraint is represented by the red disk. The first point where the elliptical contours hit the constraint region is the solution of ridge regression. *\(\)* regularization will keep all predictors by jointly shrinking the corresponding coefficients. It also reduces the possible solution to those points in the intersection of two contours. The intersection is a much smaller set than the original parameter space. Therefore it reduces the complexity of the model and smooths it.

*\(\)* regularization, instead, which uses a penalty term of *\(\)* norm, encourages the sum of the absolute values of the parameters to be small. Problem (\ref{eq:LS}) then becomes Lasso regression, which can be expressed as:

\begin{eqnarray}\label{eq:L1}

\hat\beta =\mathrm{arg}\max_{\beta}\sum_{j=1}^{n}(y_j-\sum_{i=1}\beta_j\phi_i(x_j))^2+\lambda\sum_i|\beta_i|

\end{eqnarray}

Unlike the *\(\)* regularization, the *\(\)* constraint is represented by a red diamond, seen in Figure 3. The diamond has corners; if the solution occurs at a corner, then it has one parameter \(\) equal to zero.

Lasso regression uses this shrinkage mechanism to zero out some parameters \(\) and de-select the corresponding features \(\). Due to its strong tends of setting some parameters to zeros, it is often used to select features when we know that some features are really very sparse.

Elastic net regularization is a tradeoff between *\(\)*and *\(\)* regularization and has a penalty which is a mix of *\(\)* and *\(\)* norm. It can perform the function of feature selection while still not imposing too much sparsity on the features (discarding too many features) by imposing a mixture of *\(\)* and *\(\)* regularization on parameters \(\), seen in equ.(\ref{eq:L12}).

\begin{eqnarray}\label{eq:L12}

\hat\beta =argmax_{\beta}\sum_{j=1}^{n}(y_j-\sum_{i=1}\beta_j\phi_i(x_j))^2+\lambda_1\sum_i|\beta_i|+\lambda_2\sum_i\beta_i^2

\end{eqnarray}

The selection of different penalties depends on problems. If the signals are truly sparse, then *\(\)* or *\(\)* penalty can be used to select the hidden signals from noisy data while it is almost impossible for *\(\)* to fully recover the the sparse signals. For problems with features not sparse at all, I often find the *\(\)* regularization often outperforms *\(\)* regularization. In the prediction application, ridge regression with *\(\)* is more common and often recommended for many modeling. However in the case where you have many features and want to reduce the complexity of the model by de-selecting some features, you may want to impose *\(\)* penalty or go for more of a balanced approach like elastic net.

Therefore, it is best to collect as many samples as possible. Even with a lot samples, a simpler model with *\(\)* regularization will often perform better than other choices.

For more on regularization, be sure to read these posts in the SAS Community: