Overfitting and Regularization
When models memorize instead of generalize, and the standard techniques — from data to penalty terms — that prevent it.

Overfitting is the failure mode in which a machine learning model fits its training data extremely well but performs poorly on new data. The model has effectively memorized the training set — including its noise and accidents — instead of learning the underlying pattern. The complementary failure, underfitting, occurs when a model is too simple to capture the pattern at all. The tension between the two is classically described as the bias–variance tradeoff: simple models have high bias (systematic error) and low variance (stable predictions), while flexible models have low bias and high variance (sensitive to the particular training sample). Overfitting is the high-variance end of that tradeoff.
Detection requires separating the data. The standard protocol splits the dataset into a training set, a validation set used for tuning, and a final test set used exactly once. During training, the training error falls steadily while the validation error eventually rises — the classic overfitting signature, visible directly on learning curves. Cross-validation (k-fold) reuses the data by training on k−1 folds and validating on the remaining one, rotating, and averaging, giving a more reliable estimate when data are scarce.
Regularization is the family of techniques that deliberately constrain the model to prevent overfitting:
| Technique | Mechanism | Typical effect |
|---|---|---|
| L2 (ridge, weight decay) | Penalty on squared weights | Shrinks weights, smooths model |
| L1 (lasso) | Penalty on absolute weights | Drives some weights to zero, selects features |
| Early stopping | Stop when validation error rises | Limits effective training time |
| Dropout | Randomly disable units per step | Prevents co-adaptation in neural nets |
| Data augmentation | Synthesize transformed examples | Enlarges effective training set |
| Ensembles | Average many models | Reduces variance (bagging, forests) |
L2 regularization adds λ‖θ‖² to the loss, and the strength λ is a hyperparameter tuned on the validation set; too much regularization underfits. In neural networks the same idea is called weight decay, and dropout — turning off a random fraction of units during each training step — acts as an ensemble-like regularizer. Early stopping exploits the empirical fact that networks first learn general features and only later fit noise. For images, simple transformations such as cropping, flipping, and color jitter multiply the effective training set, which is often the single most effective regularizer of all.
Capacity control is the other lever: a model with fewer parameters, or a tree with limited depth, simply cannot memorize as much. Choosing the right capacity and the right regularization strength is the daily work of applied machine learning, and the discipline of keeping the test set untouched is what makes reported accuracies trustworthy. The same principles apply across decision trees, neural networks, and large language models — the latter overfit less visibly because their data are enormous, but the underlying phenomenon is identical.
Tags
machine learning overfitting regularization