CertNote/ Commute Study Notes
Roadmap
KOEN
CLF-C02 · FoundationalCloud Practitioner - Foundational
DVA-C02 · AssociateDeveloper - Associate
SAA-C03 · AssociateSolutions Architect - Associate
SOA-C02 · AssociateCloudOps Engineer - Associate
SAP-C02 · ProfessionalSolutions Architect - Professional
DOP-C02 · ProfessionalDevOps Engineer - Professional
Linux Master 2 · 2급KAIT Linux Master - Level 2
SCS-C03 · SpecialtySecurity - Specialty
Linux Master 1 · 1급KAIT Linux Master - Level 1
MLA-C01 · AssociateMachine Learning Engineer - Associate
AIF-C01 · FoundationalAI Practitioner - Foundational
DEA-C01 · AssociateData Engineer - Associate
MLS-C01 · SpecialtyMachine Learning - Specialty
  • Week 1
    • 1.The ML Lifecycle (from a Specialty Perspective)
    • 2.Data Storage for ML: S3, EFS, FSx for Lustre, and Data Formats
    • 3.Data Ingestion: Kinesis, Glue, Batch vs. Streaming
    • 4.Data Labeling: SageMaker Ground Truth, Active Learning, Label Quality
    • 5.Week 1 Comprehensive Review: ML Overview & Data Engineering 1
  • Week 2
  • Week 3
  • Week 4
  • Week 5
  • Week 6
  • Week 7
  • Week 8
    • 1.SageMaker Training Jobs: Estimator, Input Modes, Distributed Training, Spot
    • 2.Hyperparameter Tuning (AMT): Bayesian, Random, Hyperband
    • 3.Overfitting/Underfitting: Diagnosis and Regularization/Data Augmentation
    • 4.Learning Optimization: Batch Size, Learning Rate, Gradient Issues, Debugger/Profiler
    • 5.Week 8 Comprehensive Review: Training, Tuning, Generalization
  • Week 9
  • Week 10
  • Week 11
  • Week 12
SQLD · 개발자SQL Developer (SQLD)

© CertNote · 주간랩스

  • About
  • Changelog
  • Contact
  • Terms
  • Privacy
← MLS-C01/Week 8/Day 3

Based on the MLS-C01 exam guide·Report an error

MLS-C01· AssociateWeek 8 · Day 3~29 min read

Day 3 - Overfitting/Underfitting: Diagnosis and Regularization/Data Augmentation

📌 Key Takeaways

  • Even if tuning gives you good hyperparameters, a model that fits the training set well but validates poorly is useless. Generalization failure goes in two directions: overfitting and underfitting.
  • High bias = underfitting (both training and validation are bad), high variance = overfitting (only training is good, with a large gap to validation). You diagnose with learning curves.
  • Overfitting remedies: more data, stronger regularization, a simpler model, fewer features, early stopping, dropout, augmentation.
  • Underfitting remedies: more complexity, more features, longer training, weaker regularization. More epochs or a bigger model must never be used against overfitting.
  • L1 drives some weights to exactly 0 (feature selection, sparsity), L2 makes all weights small (smooth shrinkage). Scalers and encoders must be fit on the training set only to avoid leakage.

Bias and Variance, Generalization Error

Generalization error decomposes into bias and variance. The exam asks you to tell these two axes apart more than it asks about code.

StateTraining errorValidation errorGapIdentity
Underfitting (high bias)HighHighSmallThe model can't even capture the training patterns
IdealLowLowSmallBias plus variance is at its minimum
Overfitting (high variance)LowHighLargeThe 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.

Reading Learning Curves — Diagnosis

[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 Mapping

DiagnosisRemedy
OverfittingMore data, stronger regularization, simpler model, fewer features, early stopping, dropout, data augmentation
UnderfittingHigher 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.

Regularization 1: L1, L2, ElasticNet

Add a weight-magnitude penalty to the loss function to reduce variance.

TechniquePenaltyEffect
L1 (Lasso)Sum of absolute values of weightsSome weights become exactly 0 → feature selection (sparsity)
L2 (Ridge)Sum of squares of weightsWeights become small (but not 0) → smooth shrinkage
ElasticNetL1 + L2 combinationA 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:

  • "There are too many features; I want unnecessary ones discarded automatically and a sparse model" → L1
  • "I want to keep every feature but shrink the weights to curb overfitting" → L2

Regularization 2: Dropout, Early Stopping

These are the two techniques used mainly in deep learning.

  • Dropout: Randomly deactivates neurons at each step (e.g., rate 0.5). It prevents reliance on specific neurons and gives an implicit ensemble effect. It is turned off at inference, with the weights adjusted to compensate.
  • Early Stopping: Stops training when validation loss no longer improves. It cuts training off before reaching the point of overfitting.
# 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.

Regularization Technique Selection Table

TechniqueWhat it reducesWhen to useWhen NOT to use
L1 (Lasso)Variance + number of featuresVery many features with a large share irrelevant; the goal is a sparse model or feature selectionWhen every feature is meaningful and none may be dropped
L2 (Ridge)VarianceWhen you need to keep all features but press the weights down; many correlated featuresWhen you actually need to remove features and make the model sparse
ElasticNetVariance + number of featuresYou want sparsity, but there are correlated feature groups for which L1 alone is unstableWhen you can't afford to add more hyperparameters to tune
DropoutVarianceNeural networks with many parameters and capacity that is large relative to the dataA model that already underfits; the inference stage (always turn it off)
Early stoppingVarianceWhen you observe a curve where validation loss rises again; also saves training timeWhen 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.

Data Augmentation

When it is hard to collect more data, you transform the existing data to widen the training distribution. It is powerful for mitigating overfitting.

DomainAugmentation techniqueCaution
ImagesRotation, flipping, cropping, brightness/contrast adjustment, noise addition, cutoutTransformations that change the label's meaning are forbidden (e.g., flipping the digit 6 into 9)
TextSynonym replacement, back-translation, random deletionIf the meaning flips, the label breaks
Tabular/imbalancedSynthesize the minority class with SMOTE, oversampling, class weightsMust be applied to the training set only, after splitting, to avoid leakage

Discriminating signals:

  • "Little data and overfitting / the cost of collecting more is very high" → data augmentation
  • "The minority class is so rare that the model learns only the majority class" → SMOTE/oversampling (or class weights)

Data Splitting and Leakage Prevention

To measure generalization honestly, the split has to be right first.

  • train / validation / test three-way split. Use the validation set to choose hyperparameters, and score the test set only once, at the very end.
  • k-fold cross-validation: When data is small, average the performance so the result doesn't depend on the luck of the split.
  • Leakage: When future information, features derived from the target, or test information get mixed into training, the validation score comes out unrealistically high.

Leakage Type Table

TypeHow it arisesSymptomPrevention
Preprocessing leakageScaler, encoder, or missing-value imputer is fit on the entire datasetValidation score is much higher than real productionfit on the training set only; use transform only for the rest
Target leakageA feature derived from the target is included in the inputA single feature dominates performanceVerify feature creation time against the prediction time
Temporal leakagePredicting the past using future dataOnly the backtest is good, then collapses in productionUse a chronological split for time series
Duplicate leakageThe same sample exists in both training and testUnrealistic test scoreRemove duplicates before splitting, split by group
Augmentation leakageSMOTE or augmentation applied before splittingSynthetic copies get mixed into the validation setAugment 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)

What Do You Measure Generalization With — Interpreting Metrics

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.

SituationMetric to look atReason
Classification with balanced classesAccuracy + train/validation gapHere accuracy moves honestly
Imbalanced classification (fraud detection, anomaly detection)F1, AUC, Recall, PR curveIf positives are 1%, predicting "all negative" gives 99% accuracy — accuracy is a trap
Missing a case is fatal (disease, fraud)Recall firstThe cost of a false negative is greater than that of a false positive
False alarms are costlyPrecision firstFalse positives create real operational cost
RegressionTrain/validation gap of RMSE / MAESensitivity to outliers differs, so choose to fit the objective
Data is small and the validation score fluctuatesk-fold CV mean ± deviationYou 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.

Diagnosis and Remedy Decision Tree

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 Mapping

Question cueAnswer to pickReason
"Training 98%, validation 71%, a large gap"Overfitting → stronger regularization · more dataClassic high-variance pattern
"Training and validation accuracy are both around 65%"Underfitting → more complexity · features · training timeClassic 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 stoppingCut 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 weightsRelieves the imbalance itself
"StandardScaler was fit on the entire dataset"Leakage → fit on the training set onlyTest statistics leak into training
"Overfitting, so double the epochs"Wrong optionIt makes overfitting worse

The next post covers training stability itself — batch size, learning rate schedules, vanishing/exploding gradients, and SageMaker Debugger/Profiler.

📖 Glossary

  • Generalization: The property that performance holds on new data not used for training. It is the model's real goal.
  • Bias / variance: The error caused by a model being too simple / how much the result swings when the training data changes only slightly. High bias means underfitting, high variance means overfitting.
  • Learning curve: A graph of how training and validation loss change with epochs or data volume. The first-line tool for diagnosing overfitting and underfitting.
  • Regularization: A family of techniques that add a penalty to the loss to keep the model from becoming overly complex.
  • Sparsity: The state where most weights become 0 and few features are actually used. L1 induces it. wd (weight decay) is, conversely, another name for L2.
  • Dropout / early stopping: A technique that randomly switches off some neurons during training to prevent reliance on specific neurons (turned off at inference) / a technique that stops training when validation loss no longer improves, so it doesn't pass the point where overfitting begins.
  • Data augmentation: Creating new training samples by transforming existing data, such as image rotation or text back-translation.
  • SMOTE: An oversampling technique that creates synthetic samples by interpolating between minority-class samples. Used to relieve class imbalance.
  • Data leakage: The phenomenon where information that should be unknowable at training time gets mixed into the model and inflates performance. Only the validation score becomes unrealistically good.
  • k-fold CV: A method that splits the data into k pieces, validates on each in turn, and averages the performance. Used when data is small and results depend on the luck of the split.

📝 Practice Questions

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?

PreviousHyperparameter Tuning (AMT): Bayesian, Random, HyperbandWeek 8 · Day 2Next Learning Optimization: Batch Size, Learning Rate, Gradient Issues, Debugger/ProfilerWeek 8 · Day 4

Official references

  • MLS-C01 official exam page(opens in a new tab)

On this page

  • Key Takeaways
  • Bias and Variance, Generalization Error
  • Reading Learning Curves — Diagnosis
  • Diagnosis → Remedy Mapping
  • Regularization 1: L1, L2, ElasticNet
  • Regularization 2: Dropout, Early Stopping
  • Regularization Technique Selection Table
  • Data Augmentation
  • Data Splitting and Leakage Prevention
  • Leakage Type Table
  • What Do You Measure Generalization With — Interpreting Metrics
  • Diagnosis and Remedy Decision Tree
  • Question Cue → Answer Mapping
  • Glossary
  • Practice Questions