Curious Pandas

Memorising is not learning

A model can score perfectly on its practice questions and fail the exam. Make one overfit on purpose, and learn the habit that catches it.

15 min+40 XP for finishing

Imagine a student who memorises the answers to last year’s exam, word for word. On last year’s paper they score 100%. On this year’s paper, with new questions, they’re lost. They learned the answers, not the subject.

Models do exactly this. It’s called overfitting: the model fits its training examples, including their noise and accidents, so closely that it stops working on anything new. The defence is just as simple as the problem. Hold some examples back. Never train on them, and judge the model only on how it does with those.

That’s what the dots with a white ring have been all along: the test set. “Test accuracy” in these widgets is always measured on them, never on the training dots.

Make it overfit, on purpose

Set this up exactly, then train for about twenty seconds and keep your eye on two numbers:

  1. Drag Noise up to 0.5. The two classes now overlap, so some dots sit on the “wrong” side purely by chance.
  2. The network is already big: two hidden layers of 12, with every input ticked (265 knobs).
  3. Set the learning rate to 1 and press Train.
Too many knobs, too much noise
epoch0
train loss-
test accuracy-
knobs-
neurons per layer, e.g. 4,4 - empty for none
Inputs the network can see

Watch train loss fall towards zero as the boundary grows tentacles to wrap around individual noisy dots. Now watch test accuracy. When we built this lesson, with these exact settings, it peaked around 83% early on and then fell to about 72% as training went on. The model got better at the dots it had seen and worse at the ones it hadn’t.

Three ways back

  • Fewer knobs. Try 4 in Hidden layers and only x and y. A smaller model can’t memorise the noise, so it’s forced to learn the broad shape.
  • Stop early. Watch the test accuracy and keep the knobs from its best moment, before memorisation set in.
  • More, cleaner data. Noise is what gets memorised. More examples make each accident matter less.

Now earn it. Keep the noise at 0.3 or more and get 85% on the held-back dots. Big networks tend to lose this one; small ones tend to win.

Generalise, don't memorise
epoch0
train loss-
test accuracy-
knobs-
neurons per layer, e.g. 4,4 - empty for none
Inputs the network can see

Check yourself+10 XP

Training loss keeps going down while test accuracy goes down too. What's happening?

Check yourself+10 XP

Why must the test examples never be used for training?

Sources

Finished reading?

Missions and quizzes above earn their own XP. This marks the lesson done.