2.6.2Model Evaluation & Selection

Underfitting vs overfitting diagnosis

3,026 words14 min readdifficulty · medium6 backlinks

Overview

The central challenge in machine learning: your model must generalize to unseen data. Underfitting and overfitting are the two failure modes, and diagnosing which one you have determines your next move. This note teaches you how to read the signs and take action.


Core Concepts


Diagnostic Framework: The Three Lenses

1. Learning Curves Analysis

2. Training vs Validation Error Gap

3. Error Components Analysis


Diagnosis Decision Tree

Recall The Diagnosis Algorithm (Explain to a 12-year-old)

Imagine you're learning to throw darts: Step 1: Look at your training board (practice throws)

  • Are you missing the bullseye by a lot? → You haven't learned the basics (underfitting)
  • Are you hitting the bullseye perfectly? → Move to step 2 Step 2: Look at the test board (new game)
  • Are you still hitting well? → You're skilled! (good fit)
  • Are you missing badly? → You memorized that specific practice board, not real dart skills (overfitting) The fix:
  • If step 1 failed: Practice more basics, improve your stance (increase model capacity)
  • If step 2 failed: Practice on many different boards, not just one (get more data, use regularization)

Formal decision tree:

START: Train your model
    ↓
Is J_train high (>> ε*)?
    ├─ YES → UNDERFITTING
    │   └─ Action: Increase capacity, remove regularization,
    │              engineer features, train longer
    │
    └─ NO → Is (J_cv - J_train) large?
        ├─ YES → OVERFITTING
        │   └─ Action: More data, regularization (L1/L2/dropout),
        │              reduce capacity, data augmentation
        │
        └─ NO → Is J_cv acceptable (≈ ε*)?
            ├─ YES → GOOD FIT (done!)
            └─ NO → HIGH IRREDUCIBLE ERROR
                └─ Action: Better features, cleaner data,
                           redefine problem

Common Mistakes


Practical Diagnostic Checklist

Quick Diagnosis (30 seconds)

  1. Compute: JtrainJ_{train}, JcvJ_{cv}, baseline ϵ\epsilon^*
  2. Check:
    • Is JtrainϵJ_{train} \gg \epsilon^*? → Underfitting
    • Is (JcvJtrain)(J_{cv} - J_{train}) large (>10% of ϵ\epsilon^*)? → Overfitting
  3. Act: See decision tree above

Deep Diagnosis (when quick check is unclear)

  1. Plot learning curves: Error vs mm (training set size)

    • Underfitting: Both curves plateau high
    • Overfitting: Large persistent gap
  2. Plot validation curves: Error vs model complexity

    • Underfitting: Error decreases as complexity increases
    • Overfitting: Training error decreases, validation error increases (U-shape)
  3. Compute error budget:

    Avoidable bias = J_train - ε*
    Variance = J_cv - J_train
    Focus on the larger component (80/20 rule)
    
  4. Sanity checks:

    • Can your model fit a single batch perfectly? (No → architecture issue)
    • Does validation error decrease at all during training? (No → data/feature issue)
    • Is training loss still decreasing? (Yes → might benefit from more training)

Action Playbook

To Fix Underfitting (High Bias)

| Action | Why It Works | When To Use | |--------|-------------| | Increase model capacity | Allows model to represent complex patterns | JtrainJ_{train} high, gap small | | Add polynomial features | Captures non-linear relationships | Linear model on curved data | | Reduce regularization | Removes constraints on model flexibility | λ\lambda too high | | Train longer | Allows optimization to converge | Loss still decreasing | | Remove dropout/L2 | Same as reduce regularization | Regularization too aggressive |

To Fix Overfitting (High Variance)

| Action | Why It Works | When To Use | |--------|-------------| | Get more training data | Provides more constraints | (JcvJtrain)(J_{cv} - J_{train}) large | | Data augmentation | Artificially increases data diversity | Can't get more real data | | Add regularization (L1/L2) | Penalizes model complexity | Gap large, enough data | | Add dropout | Forces redundant representations | Deep neural networks | | Reduce model capacity | Limits memorization ability | Severe overfitting | | Early stopping | Stops before memorization dominates | Validation error U-shaped | | Ensemble methods | Averages out individual model variance | Production system |


Connections



Flashcards

#flashcards/ai-ml

What are the two failure modes of model generalization? :: Underfitting (high bias) and overfitting (high variance)

What is the mathematical signature of underfitting?
High training error JtrainϵJ_{train} \gg \epsilon^* AND small gap (JcvJtrain)(J_{cv} - J_{train}) is small
What is the mathematical signature of overfitting?
Low training error Jtrain0J_{train} \approx 0 AND large gap (JcvJtrain)0(J_{cv} - J_{train}) \gg 0
In learning curves, what pattern indicates underfitting?
Both training and validation error curves plateau at a HIGH value
In learning curves, what pattern indicates overfitting?
Large persistent gap between training (low) and validation (high) error curves, gap decreases slowly with more data
What is the formula for avoidable bias?
Avoidable bias = JtrainϵJ_{train} - \epsilon^* where ϵ\epsilon^* is human-level or Bayes error
What is the formula for variance in error budget analysis?
Variance = JcvJtrainJ_{cv} - J_{train} (the generalization gap)
If both training and validation errors are 40% and human-level is 5%, what is the diagnosis?
Underfitting (high bias) - small gap but both errors are far from baseline
If training error is 2% and validation error is 25 with human-level at 3%, what is the diagnosis?
Overfitting (high variance) - large gap, training near baseline but validation far above
What are three ways to fix underfitting?
1) Increase model capacity, 2) Add polynomial/interaction features, 3) Reduce regularization
What are three ways to fix overfitting?
1) Get more training data, 2) Add regularization (L1/L2/dropout), 3) Reduce model capacity or use early stopping
Why doesn't training longer help overfitting?
Training longer on the same data gives the model more time to memorize noise, making overfitting worse; you need more DATA not more epochs
What does a small train-test gap with high errors indicate?
Underfitting - the model is "consistently bad" at fitting even the training data
What should you compare your training error against?
A baseline error ϵ\epsilon^* (human-level performance or theoretical minimum) to measure avoidable bias
According to the 80/20 rule for error budget, where should you focus effort?
Focus on whichever is larger: avoidable bias (JtrainϵJ_{train} - \epsilon^*) or variance (JcvJtrainJ_{cv} - J_{train})

Concept Map

two failure modes

two failure modes

model too simple

high plateau, small gap

model too complex

large gap

compared with

difference gives

plots Jtrain and Jcv vs size

reveals

small gap high error

large gap

Generalization to unseen data

Underfitting - High Bias

Overfitting - High Variance

Training error Jtrain

Test error Jcv

Generalization gap

Learning curves

Diagnosis

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, machine learning mein sabse bada problem ye hai ki tumhara model nayi data pe kaisa perform karega. Training data pe toh bahut acha kar raha hai, lekin real world mein test karo toh fail ho jata hai - yeh overfitting kehte hain. Ya phir ulta, training data pe bhi thek se kuch seekh nahi paya - yeh underfitting hai.

Diagnosis kaise karein? Teen chezein dekho: pehla, learning curves banao (error vs training examples ka graph). Agar dono curves (training aur validation) upar hi ruk gaye high error pe, matlab model itna simple hai ki pattern hi samajh nahi aa raha - underfitting. Agar training error bahut kam hai lekin validation error bahut zyada, aur unke bech bada gap hai, toh model ne training data ko ratt liya hai instead of learning general pattern - overfitting. Dosra tareka hai error budget analysis: apni training error ko baseline (jaise human-level performance) se compare karo. Agar J_train >> baseline, toh capacity badhao (underfitting fix). Agar

Go deeper — visual, from zero

Test yourself — Model Evaluation & Selection

Connections