Objectives
By the end of this lesson, you will be able to:
- Describe training as a loop of guessing, measuring error and adjusting
- Explain overfitting and how a test set reveals it
- Explain why accuracy alone can mislead, using false positives and false negatives
Key terms
- Loss
- A number that measures how wrong a model's answers are. Training tries to make it smaller.
- Overfitting
- When a model memorizes its training examples, including their quirks, and performs poorly on new ones.
- False positive
- The model says yes when the true answer is no.
- False negative
- The model says no when the true answer is yes.
Reading
The training loop
Training repeats four steps. The model makes a guess on some examples. We compare its guesses with the correct answers and compute a number, the loss, that says how wrong it was. An algorithm works out which way to nudge each weight to shrink the loss. The weights are nudged slightly. Then the loop repeats, often millions of times.
Picture walking down a hill in thick fog. You cannot see the bottom, but you can feel which way the ground slopes under your feet. Take a small step downhill, feel again, step again. Training is that walk, where height is the loss.
Overfitting: learning too much
Push training too far on too little data, and a model starts memorizing its training examples, including their accidents and noise. Its training score climbs toward perfect while its performance on new examples gets worse. This is overfitting.
It is the student who memorized last year's answer sheet. The hidden test set from Unit 2 is how we catch it: a wide gap between the training score and the test score is the warning sign. The usual remedies are more varied data, a simpler model, or stopping training earlier.
Accuracy is not the whole story
Accuracy is the share of answers a model gets right. It sounds like all you need, and it can badly mislead. Suppose a condition affects 1 person in 100. A model that says "no" to everyone is 99% accurate and completely useless.
So we look at the kinds of mistakes. A false positive is a false alarm: a spam filter that hides a real email. A false negative is a miss: a spam filter that lets spam through. Which is worse depends on the situation. For a medical screening test, a miss may be far more serious than a false alarm that leads to a follow-up check.
Choosing which mistake to tolerate is a decision about values, and people must make it. The model cannot.
Try it · Interactive lab
Set the spam cut-off
A spam detector has scored 20 messages. You decide the cut-off. Drag the slider and watch the two kinds of mistake trade off.
Spam Real mail Mistake
- Spam caught
- 7
- Real mail kept
- 8
- False alarmsreal mail hidden
- 3
- Missesspam let through
- 2
- Accuracy
- 75%
Try this: find the cut-off with zero false alarms, then the one with zero misses. Can any single cut-off give you both?
Group activity 25 min
Tune the detector
You will need
- 20 cards, each with a number from 1 to 10 (a "suspicion score") and a hidden true label on the back (15 Safe, 5 Problem), arranged so that scores overlap between the two labels
- A table for counting correct answers, false positives and false negatives
- 1
Lay the cards out in order of suspicion score, labels hidden.
- 2
Choose a threshold: every card above it will be flagged as a Problem. Flip the cards and count correct answers, false positives and false negatives.
- 3
Move the threshold lower and count again. Move it higher and count again.
- 4
Decide which threshold you would use if the detector were (a) a spam filter and (b) a smoke alarm. Explain why your answers differ.
Discuss
- Q1
No threshold removed both kinds of mistake. Why not?
- Q2
For a system that flags possible cheating on exams, which mistake is worse? Who bears the cost of each?
- Q3
A company announces its model is "99% accurate." What two questions would you ask?
Write your answer to one of the questions. Saved only on this device.
Quick check
Choose an answer to see whether you were right, and why.
Key takeaways
- Training is a loop: guess, measure the error, adjust, repeat.
- Overfitting is memorizing instead of learning; a test set exposes it.
- Look past accuracy to the kinds of mistakes, and decide which matter most.