Regularization
Regularization is an important algorithm-dependent technique to reduce model Variance (preventing overfitting) while introducing a slight amount of Bias. It achieves this by adding a penalty term directly into the cost function to restrict the flexibility of the parameters.
Visualizing the Need
Consider a highly-flexible polynomial hypothesis:
If left unchecked, this model represents high variance and will perfectly mold to training noise. To prevent extremely large weights that exaggerate curves, we formulate a Regularized Cost Function:
- The first term establishes the standard MSE cost.
- The second component acts as the regularization penalty term.
- (lambda) defines the regularizing hyperparameter. It controls the "power" or severity of the penalty.
Crucial Rule: The validation error must always be calculated using the original cost function (without the regularization penalty), not the regularized one. Regularization is merely a tool for optimization during Gradient Descent model training.
Types of Regularization: and
-Norm (Lasso Regularization)
The penalty term consists of the absolute values of the weights.
Cost expression:
- Characteristic Property: It uniquely leads to high sparsity. Many parameter coefficients () are forced to become exactly zero. Consequently, Lasso inadvertently performs automated feature selection by eliminating unimportant features.
-Norm (Ridge Regularization)
The penalty term consists of the squared magnitude of the weights.
Cost expression:
- Characteristic Property: Makes the model parameters stable and smooth by heavily penalizing aggressively large individual weights. Features rarely become absolutely zero, but they are distributed smoothly.
Gradient Descent Update
Regardless of the type of regularization used, the process of minimizing the error remains conceptually identical—we take the partial derivative of the overall cost function iteratively: