# Regularized Regression¶

Regression models, especially those fit to high-dimensional data, may be prone to overfitting. One way to ameliorate this issue is by penalizing the magnitude of the \(\bbetahat\) coefficient estimates. This has the effect of shrinking these estimates toward 0, which ideally prevents the model from capturing spurious relationships between weak predictors and the target variable.

This section reviews the two most common methods for regularized regression: Ridge and Lasso.

## Ridge Regression¶

Like ordinary linear regression, Ridge regression estimates the coefficients by minimizing a loss function on the training data. Unlike ordinary linear regression, the loss function for Ridge regression penalizes large values of the \(\bbetahat\) estimates. Specifically, Ridge regression minimizes the sum of the RSS and the L2 norm of \(\bbetahat\):

Here, \(\lambda\) is a *tuning parameter* which represents the amount of regularization. A large \(\lambda\) means a greater penalty on the \(\bbetahat\) estimates, meaning more shrinkage of these estimates toward 0. \(\lambda\) is not estimated by the model but rather chosen before fitting, typically through cross validation.

Note

Note that the Ridge loss function does *not* penalize the magnitude of the intercept estimate, \(\hat{\beta}_0\). Intuitively, a greater intercept does not suggest overfitting.

As in ordinary linear regression, we start estimating \(\bbetahat\) by taking the derivative of the loss function. First note that since \(\hat{\beta}_0\) is not penalized,

where \(I'\) is the identity matrix of size \(D+1\) *except* the first element is a 0. Then, adding in the derivative of the RSS discussed in chapter 1, we get

Setting this equal to 0 and solving for \(\bbetahat\), we get our estimates:

## Lasso Regression¶

Lasso regression differs from Ridge regression in that its loss function uses the L1 norm for the \(\bbetahat\) estimates rather than the L2 norm. This means we penalize the sum of absolute values of the \(\hat{\beta}\)s, rather than the sum of their squares.

As usual, let’s then calculate the gradient of the loss function with respect to \(\bbetahat\):

where again we use \(I'\) rather than \(I\) since the magnitude of the intercept estimate \(\hat{\beta}_0\) is not penalized.

Unfortunately, we cannot find a closed-form solution for the \(\bbetahat\) that minimize the Lasso loss. Numerous methods exist for estimating the \(\bbetahat\), though using the gradient calculated above we could easily reach an estimate through gradient descent. The construction in the next section uses this approach.