Based on the MLS-C01 exam guideReport an error
fit on the training set only to avoid leakage.Generalization error decomposes into bias and variance. The exam asks you to tell these two axes apart more than it asks about code.
| State | Training error | Validation error | Gap | Identity |
|---|---|---|---|---|
| Underfitting (high bias) | High | High | Small | The model can't even capture the training patterns |
| Ideal | Low | Low | Small | Bias plus variance is at its minimum |
| Overfitting (high variance) | Low | High | Large | The model memorizes noise |
Underfitting: train error ↑ valid error ↑ (both bad, small gap)
Ideal: train error ↓ valid error ↓ (both good)
Overfitting: train error ↓ valid error ↑ (the gap is large)The bias-variance tradeoff is the fundamental tension between model complexity and generalization. Raising complexity lowers bias but increases variance; lowering it does the opposite. The goal is to find the point where the sum (bias + variance) is minimal. Regularization reduces variance to fight overfitting, while adding model capacity or features reduces bias to fight underfitting.
[Overfitting signals]
loss │╲ ← validation loss rises again after some point
│ ╲___ valid accuracy: train 99% / valid 72% (large gap)
│ ╲ ╱‾‾‾ as epochs go on, only train loss keeps falling
│ ╲_╱
│ ╲_______ train
└──────────────── epoch
↑ this is the early stopping point
[Underfitting signals]
loss │‾‾‾‾‾‾‾‾‾‾‾ valid accuracy: train 65% / valid 64% (both low and similar)
│‾‾‾‾‾‾‾‾‾‾‾ train more training leaves the loss high and flat (plateau)
└──────────────── epoch
[Ideal]
loss │╲___
│ ╲___╲______ valid both curves fall together and end close to each other at a low value
│ ╲_________ train
└──────────────── epoch| Diagnosis | Remedy |
|---|---|
| Overfitting | More data, stronger regularization, simpler model, fewer features, early stopping, dropout, data augmentation |
| Underfitting | Higher model complexity, more features, longer training, weaker regularization |
⚠️ Trap: Any option that answers overfitting with "double the epochs / stack more layers" is wrong. Both increase variance even more. Likewise, "merge the validation set into the training set" is wrong because it removes the ability to measure generalization at all.
Add a weight-magnitude penalty to the loss function to reduce variance.
| Technique | Penalty | Effect |
|---|---|---|
| L1 (Lasso) | Sum of absolute values of weights | Some weights become exactly 0 → feature selection (sparsity) |
| L2 (Ridge) | Sum of squares of weights | Weights become small (but not 0) → smooth shrinkage |
| ElasticNet | L1 + L2 combination | A compromise between sparsity and stability |
# Example: L1/L2 strength in Linear Learner
hyperparameters = {
"l1": 0.01, # L1 strength (sparsity)
"wd": 0.001, # weight decay = L2
}Discriminating signals:
These are the two techniques used mainly in deep learning.
# Example: neural network hyperparameters
hyperparameters = {
"dropout": 0.5,
"early_stopping_patience": 5, # stop if no improvement for 5 epochs
}Dropout trains a different sub-network at every step and, at inference, effectively averages them, so it works as an implicit ensemble. Early stopping halts training right before noise memorization begins, which reduces variance. Both achieve the same goal of "making the effective model simpler" in different ways.
| Technique | What it reduces | When to use | When NOT to use |
|---|---|---|---|
| L1 (Lasso) | Variance + number of features | Very many features with a large share irrelevant; the goal is a sparse model or feature selection | When every feature is meaningful and none may be dropped |
| L2 (Ridge) | Variance | When you need to keep all features but press the weights down; many correlated features | When you actually need to remove features and make the model sparse |
| ElasticNet | Variance + number of features | You want sparsity, but there are correlated feature groups for which L1 alone is unstable | When you can't afford to add more hyperparameters to tune |
| Dropout | Variance | Neural networks with many parameters and capacity that is large relative to the data | A model that already underfits; the inference stage (always turn it off) |
| Early stopping | Variance | When you observe a curve where validation loss rises again; also saves training time | When there is no validation set or it is so small that the metric fluctuates |
⚠️ Trap: Dropout and batch normalization are not "feature selection" techniques. The answer to a statement like "the model zeroes out unnecessary features by itself" is always L1.
When it is hard to collect more data, you transform the existing data to widen the training distribution. It is powerful for mitigating overfitting.
| Domain | Augmentation technique | Caution |
|---|---|---|
| Images | Rotation, flipping, cropping, brightness/contrast adjustment, noise addition, cutout | Transformations that change the label's meaning are forbidden (e.g., flipping the digit 6 into 9) |
| Text | Synonym replacement, back-translation, random deletion | If the meaning flips, the label breaks |
| Tabular/imbalanced | Synthesize the minority class with SMOTE, oversampling, class weights | Must be applied to the training set only, after splitting, to avoid leakage |
Discriminating signals:
To measure generalization honestly, the split has to be right first.
| Type | How it arises | Symptom | Prevention |
|---|---|---|---|
| Preprocessing leakage | Scaler, encoder, or missing-value imputer is fit on the entire dataset | Validation score is much higher than real production | fit on the training set only; use transform only for the rest |
| Target leakage | A feature derived from the target is included in the input | A single feature dominates performance | Verify feature creation time against the prediction time |
| Temporal leakage | Predicting the past using future data | Only the backtest is good, then collapses in production | Use a chronological split for time series |
| Duplicate leakage | The same sample exists in both training and test | Unrealistic test score | Remove duplicates before splitting, split by group |
| Augmentation leakage | SMOTE or augmentation applied before splitting | Synthetic copies get mixed into the validation set | Augment only the training set, after splitting |
[Correct order]
Raw data
│
① Split (train / validation / test) ← from here on, every fit uses the training set only
│
② Impute missing values · encode · scale (fit on train → transform everything)
│
③ Augment / SMOTE (train only)
│
④ Train → choose hyperparameters with the validation set (adjust regularization strength here)
│
⑤ Score the test set once (for the final report)To look at the gap, you first need to be sure which number the gap is between. If you pick the wrong metric, the overfitting/underfitting diagnosis itself goes astray.
| Situation | Metric to look at | Reason |
|---|---|---|
| Classification with balanced classes | Accuracy + train/validation gap | Here accuracy moves honestly |
| Imbalanced classification (fraud detection, anomaly detection) | F1, AUC, Recall, PR curve | If positives are 1%, predicting "all negative" gives 99% accuracy — accuracy is a trap |
| Missing a case is fatal (disease, fraud) | Recall first | The cost of a false negative is greater than that of a false positive |
| False alarms are costly | Precision first | False positives create real operational cost |
| Regression | Train/validation gap of RMSE / MAE | Sensitivity to outliers differs, so choose to fit the objective |
| Data is small and the validation score fluctuates | k-fold CV mean ± deviation | You have to remove the luck of a single split for the gap to be trustworthy |
With imbalanced data, "train 99% / validation 98%" with a small gap must not be taken as good generalization. Both numbers may simply be pulled along by the majority class. You have to look at the confusion matrix and the minority-class Recall together.
Model performance falls short of expectations
├─ Is the training performance itself low?
│ ├─ Yes → underfitting (high bias)
│ │ ├─ increase model complexity (layers · tree depth · add features)
│ │ ├─ lower regularization strength (ease L1/L2/dropout)
│ │ └─ train longer (more epochs)
│ └─ No ↓
├─ Is training good but the gap to validation large?
│ ├─ Yes → overfitting (high variance)
│ │ ├─ Can you collect more data?
│ │ │ ├─ Yes → add data
│ │ │ └─ No → data augmentation (images: rotation·crop / text: back-translation)
│ │ ├─ Too many features, with some irrelevant? → L1
│ │ ├─ Need to keep every feature and press down? → L2
│ │ ├─ Is it a neural network? → dropout
│ │ └─ Does validation loss rise again? → early stopping
│ └─ No ↓
└─ Is the validation score unrealistically high?
└─ Yes → suspect data leakage (check the fit scope of preprocessing · target-derived features · duplicates)| Question cue | Answer to pick | Reason |
|---|---|---|
| "Training 98%, validation 71%, a large gap" | Overfitting → stronger regularization · more data | Classic high-variance pattern |
| "Training and validation accuracy are both around 65%" | Underfitting → more complexity · features · training time | Classic high-bias pattern |
| "Out of 500 features, I want the unnecessary ones set to 0" | L1 (Lasso) | The absolute-value penalty drives weights to exactly 0 |
| "Keep all features but only reduce the weights" | L2 (Ridge) | Shrinks toward 0 but doesn't eliminate |
| "Image overfitting, but labeling cost is high" | Data augmentation (rotation · flip · crop) | Widens the training distribution without collecting more |
| "Training loss keeps falling but validation loss rises again" | Early stopping | Cut off at the point where noise memorization begins |
| "The minority class is only 1%, so the model learns only the majority class" | SMOTE · oversampling · class weights | Relieves the imbalance itself |
| "StandardScaler was fit on the entire dataset" | Leakage → fit on the training set only | Test statistics leak into training |
| "Overfitting, so double the epochs" | Wrong option | It makes overfitting worse |
The next post covers training stability itself — batch size, learning rate schedules, vanishing/exploding gradients, and SageMaker Debugger/Profiler.
wd (weight decay) is, conversely, another name for L2.Click a choice to reveal the answer and explanation.
Question 1
A model shows a large gap: 98% training accuracy and 71% validation accuracy. Which diagnosis and first response are MOST appropriate for this situation?
Question 2
There are many input features (500), and you want the model to set unnecessary ones to 0 by itself to obtain a sparse model. Which regularization is MOST suitable?
Question 3
An image classification model overfits, and collecting additional labeled data is very expensive. What is the most cost-effective response?
Question 4
In a neural network, as training proceeds the training loss keeps going down, but the validation loss rises again after some point. What is the most direct technique for preventing the memorization of noise?
Question 5
When applying standardization (StandardScaler) in preprocessing, what is the correct way to prevent data leakage?