Statistical Modeling and Generalization

Model Complexity

Model complexity as the tradeoff between expressive power, fitting the signal, and resisting overfitting.

Lesson
22

Goal

Understand model complexity as a tradeoff: more expressive models can fit the training data better, but that same flexibility can make them memorize noise instead of learning the underlying pattern.

Motivation

After the Bayesian lessons, it is tempting to think the hard part of machine learning is only estimating parameters well. But there is a more basic question underneath parameter estimation:

What kind of model are we even fitting?

If the model family is too simple, it misses real structure. If it is too flexible, it can chase accidental quirks of the training data. This lesson introduces the vocabulary for that tradeoff.

Prerequisites

Notation / Symbol Table

SymbolPlain-English nameMeaning
xinputThe feature or independent variable.
youtputThe observed target value.
f(x)signalThe underlying relationship we wish to learn.
εnoiseRandom variation or measurement error.
σ²noise varianceHow spread out the noise tends to be.
y = f(x) + εsignal-plus-noise modelThe idea that observations contain both structure and randomness.

Core Ideas

Data Contains Signal And Noise

A useful mental model is

y=f(x)+ε,y = f(x) + \varepsilon,

where:

Machine learning should learn f(x), not memorize ε.

That is the whole overfitting story in one line.

Complexity Means Representational Power

Different model families can represent different kinds of functions:

This is what people mean by capacity or model complexity. Higher capacity means:

I can represent more complicated relationships.

It does not mean:

I will automatically make better predictions.

Why Training Error Usually Goes Down

As complexity increases, the model gets more degrees of freedom. That usually makes it easier to reduce training error.

This is why a high-capacity model often looks impressive on the dataset it already saw. It has enough flexibility to explain many small details, including details that do not matter outside that dataset.

The Three Regimes

There are three standard regions to keep straight.

Underfitting:

Good fit:

Overfitting:

The key point is that the best generalizing model is not necessarily the one with the smallest training error.

Generalization Is The Real Objective

Machine learning is not a contest to explain the past perfectly. It is a contest to perform well on unseen data.

That is what generalization means:

How well does the model behave on examples it did not memorize during training?

This is why we eventually need validation and test sets. We need some way to check whether the learned rule transfers beyond the training sample.

A Small Mathematical Correction Worth Keeping

In the original transcript, one thought experiment used five points and a fifth-degree polynomial. The sharper mathematical statement is:

For five distinct points, the unique interpolating polynomial has degree at most four.

A fifth-degree polynomial can still pass through the points, but then it is no longer unique. That detail does not change the lesson’s intuition. It just keeps the algebra honest.

Worked Example

Example 1: A Line Versus A Highly Flexible Polynomial

Suppose we observe:

xy
12.0
23.1
33.9
45.0
55.8

Now compare two model families:

Model B can drive training error to zero. That sounds impressive, but zero training error is not proof of good prediction. If the underlying process is roughly linear with noise, the extra wiggle is probably noise-fitting.

The sensible question is:

Which model would you trust more at x = 6?

That is a generalization question, not a training-error question.

Example 2: Two Accuracy Reports

Suppose one model achieves:

and another achieves:

The second model is usually the one you would deploy. It has learned a rule that transfers.

This is the habit to build early:

Treat perfect training performance with suspicion unless unseen-data performance confirms it.

Why This Shows Up In ML

Every serious ML workflow faces complexity choices:

The lesson also sets up several later tools:

If you remember one sentence, make it this one:

Low training error tells you the model can explain the data it saw. Generalization tells you whether that explanation survives contact with new data.

Exercises

  1. Why can a model with more parameters fit the training data better without necessarily improving test performance?
  2. Explain the difference between signal and noise in the expression y = f(x) + ε.
  3. Describe the behavioral difference between underfitting and overfitting without using formulas.
  4. Suppose adding more polynomial degrees keeps reducing training error. How would you decide when those extra degrees stop helping?

Implementation Exercise

Build a small TypeScript experiment that generates noisy points from a simple rule such as

y=x+1+ε,y = x + 1 + \varepsilon,

then compares several model families on separate training and validation splits.

A good version of the exercise should record:

You do not need a fancy plotting library to learn something here. Even a printed table is enough to make the pattern visible.

Reflection Questions