Phase 2: Classical Machine Learning · 55 min · Python · scikit-learn · Matplotlib
The Concept
The Intuition: Dartboard Model
Imagine throwing darts at a dartboard. Each throw is a model trained on a different random sample of data. The bullseye is the true pattern in the data.
- Low bias, low variance: all darts hit the bullseye. The model is accurate and consistent.
- High bias, low variance: all darts cluster tightly, but far from the bullseye. The model is consistently wrong — it can't capture the true pattern (underfitting).
- Low bias, high variance: darts scatter around the bullseye but don't cluster. The model is right on average but inconsistent — it changes dramatically depending on which training data it saw (overfitting).
- High bias, high variance: darts scatter and miss. The model is both wrong and inconsistent.
Bias is the model's systematic error — how far the average prediction is from the truth. Variance is the model's sensitivity to training data — how much predictions change when you train on different samples. The total error decomposes as:
Total Error = Bias² + Variance + Irreducible Error
The irreducible error is the noise in the data itself — no model can eliminate it. The goal is to minimize the reducible part: bias² + variance.
High Bias (Underfitting): The Model Is Too Simple
Symptoms: training error is high, test error is high, training and test errors are similar. The model can't represent the true pattern in the data.
Example: fitting a straight line to data that follows a curve. No matter how much data you give it, the line can't bend. The model is consistently wrong.
Fixes:
- Use a more complex model (deeper tree, more polynomial features, neural network)
- Reduce regularization (lower L2 penalty, increase max depth)
- Add better features (feature engineering)
- Train longer (more epochs for neural networks)
High Variance (Overfitting): The Model Is Too Complex
Symptoms: training error is low, test error is much higher. The gap between training and test performance is large. The model has memorized the training data, including its noise.
Example: a depth-20 decision tree on 100 samples. It creates a unique leaf for nearly every point — 100% training accuracy, but on new data, the specific splits it learned don't generalize.
Fixes:
- Use a simpler model (shallower tree, fewer features, lower polynomial degree)
- Increase regularization (higher L2/L1 penalty, reduce max depth)
- Get more training data (more data dilutes the noise)
- Use ensemble methods (bagging reduces variance by averaging)
- Use dropout / early stopping (for neural networks)
Your model has 98% training accuracy and 72% test accuracy. The gap is large. What problem do you have and what's the most effective first fix?
The large gap between training (98%) and test (72%) accuracy is the classic signature of high variance (overfitting). The model has memorized the training data but doesn't generalize. Effective fixes: increase regularization, reduce model complexity, get more training data, or use ensemble methods like bagging.
Learning Curves: Diagnosing with Data
A learning curve plots training and validation error as a function of training set size. It tells you whether more data will help:
- High bias: both curves plateau at a high error, close together. More data won't help — the model is too simple to capture the pattern. You need a more complex model or better features.
- High variance: training error stays low, validation error stays high, with a large gap. More data will help — it narrows the gap by giving the model more examples to average over.
- Just right: both curves converge to a low error. The model has enough capacity and enough data.
The Double Descent Phenomenon
Classical ML theory says: as model complexity increases, bias decreases and variance increases, creating a U-shaped test error curve with a "sweet spot" in the middle. But modern deep learning has revealed a surprising phenomenon called double descent: if you keep increasing complexity past the point where the model can memorize the training data, test error starts decreasing again. The model enters the "overparameterized" regime where it has so many parameters that it can fit the training data in many ways — and the smoothest solution (which gradient descent tends to find) generalizes well.
This is why modern neural networks with billions of parameters can generalize despite having far more parameters than training examples. The classical bias-variance tradeoff still holds in the "underparameterized" regime, but the story is more nuanced for deep learning.
Unlock the full lesson
You've read the first 2 sections. The rest of this lesson covers Build It, Ship It, Use It, Evaluation, Exercises, Key Terms, Common Pitfalls, Interview Framing — plus a hands-on lab, quiz, and project artifact.
Create a free account to unlock Phase 0 and Phase 1 of every course — no credit card.