What is regularization in machine learning?
Regularization is any technique that reduces overfitting by limiting how closely a model can fit its training data. The most common form adds a penalty on the size of the weights to the loss: L_total = L_data + λ·R(w), where λ sets the strength. Other forms change the training procedure instead, such as dropout and early stopping.
Almost every trained model uses some regularization. Ridge and lasso regression add L2 and L1 penalties to linear models. Deep networks typically combine weight decay, dropout, data augmentation, and early stopping. Large language models are trained with AdamW, whose decoupled weight decay is a form of L2 regularization, and many use dropout during fine-tuning.
Key ideas
- Regularization trades a little training accuracy for better performance on new data.
- L2 regularization shrinks all weights in proportion to their size.
- L1 regularization drives small weights to exactly zero and produces sparse models.
- Dropout randomly disables neurons during training so no unit can depend on another.
- Early stopping halts training when validation loss stops improving.
- The regularization strength is a hyperparameter chosen with validation data.
Short takes on this topic
Common questions
What is the difference between L1 and L2 regularization?
L1 penalizes the sum of absolute weights and tends to set many weights to exactly zero, which acts as feature selection. L2 penalizes the sum of squared weights and shrinks all of them smoothly without making them zero. Elastic net combines both penalties.
Is weight decay the same as L2 regularization?
For plain gradient descent, yes: adding λΣw² to the loss is equivalent to shrinking each weight by a constant factor every step. For adaptive optimizers such as Adam, the two differ, because Adam rescales the penalty's gradient per weight. AdamW applies the decay directly to the weights, which usually works better.
How do I choose the regularization strength λ?
Try values on a logarithmic grid, such as 0.0001, 0.001, 0.01, and 0.1, and keep the one with the best validation score. Cross-validation gives a more reliable choice when data is limited. If validation error is high and close to training error, λ is probably too large.
Is data augmentation a form of regularization?
Yes. Flipping, cropping, or adding noise to training examples creates new variations of the data, which makes memorization harder. It changes the data rather than the loss or the model, and it is one of the most effective regularizers for image and audio models.
Related explainers
- Overfitting & Underfitting — The bias-variance tradeoff and generalization
- Bias-Variance Tradeoff — Why models underfit or overfit — the fundamental decomposition
- Norms & Distance Metrics — L1, L2, cosine similarity — measuring closeness in vector spaces
- Data Augmentation — Artificially expand training data with transformed copies to reduce overfitting
- Optimizers — SGD, momentum, and Adam — smarter gradient descent
- Cross-Validation — K-fold, stratified, and leave-one-out evaluation
References
- Srivastava et al. (2014), "Dropout: A Simple Way to Prevent Neural Networks from Overfitting", JMLR
- Loshchilov & Hutter (2017), "Decoupled Weight Decay Regularization"
- Goodfellow, Bengio & Courville (2016), "Deep Learning", chapter 7: Regularization for Deep Learning
- James, Witten, Hastie & Tibshirani, "An Introduction to Statistical Learning", chapter 6: ridge regression and the lasso
Last updated
Overfit Tailor