Regularization: Penalizing Complexity to Prevent Overfitting
Regularization penalizes model complexity to prevent overfitting. It's used in training to help models generalize to new data, rather than just memorizing training examples. The footgun is applying too much, causing the model to become too simple and underfit.
WHY IT EXISTS A model trained on data can get too good at explaining that specific data. It might learn the noise and quirks of the training set, a phenomenon called overfitting. When it sees new data, it performs poorly because it memorized details instead of learning the general pattern. Regularization was invented to combat this by encouraging simpler models.
THE MENTAL MODEL Think of regularization as a 'complexity tax' on your model. During training, the model tries to minimize its error. Regularization adds a second objective: minimize complexity. The model is rewarded for being accurate but penalized for having large internal parameters (weights). It's a trade-off: accept a little more error on the training data in exchange for a simpler, more general model that will likely perform better on new data.
HOW IT WORKS Regularization adds a penalty term to the loss function that the model is trying to minimize. This term is a function of the model's parameters. For example, L2 regularization adds the sum of the squared values of all weights to the loss. This encourages the model to keep all weights small. L1 regularization adds the sum of the absolute values of the weights, which can force some weights to become exactly zero, effectively performing feature selection. The strength of this penalty is a tunable hyperparameter.
WHEN TO USE IT Use regularization as a default when training models, especially with many features (high-dimensional data) or complex architectures like deep neural networks. It is crucial when your training data is limited or noisy, as these conditions make overfitting more likely. It helps create models that are more robust and generalize better from the training set to unseen data.
WHEN NOT TO USE IT You might not need regularization for very simple models with few parameters and a large amount of clean data, where overfitting is not a risk. Applying too much regularization is also harmful. This leads to underfitting, where the model is too simple and cannot even capture the basic patterns in the training data, resulting in poor performance everywhere.
ONE CANONICAL EXAMPLE In linear regression, you try to fit a line by minimizing error. Without regularization, the model might assign huge coefficient values to fit noisy data points perfectly. With L2 regularization, the loss function becomes (error + lambda * sum of squared coefficients). Now, to minimize this total loss, the model must not only reduce its error but also keep its coefficients small, preventing any single feature from having an outsized influence and creating a smoother, more general fit.
Read the original → en.wikipedia.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.