Class 10 · Unit 3: Evaluating models · Lesson 3.3 · 40 min
The confusion matrix, from scratch
Wrong ten times can cost a farmer ₹3,000 — or ₹20,000. It depends which wrong.
Today you will: Build a confusion matrix from raw predictions · Name TP, FP, TN and FN · Put a price on each kind of mistake
Story
Hiba: “Eighty-three per cent. So it's wrong ten times in sixty. Wrong how?” ('s uncle.)
Nobody at the table can answer.
Uncle: “Because there are two ways to be wrong. It can call a sick leaf healthy. Then I don't spray, and the scab spreads through the whole row. Or it can call a healthy leaf sick. Then I spray a tree that didn't need it. One of those costs me a bag of spray. The other costs me a season.”
He puts the tablet down.
Hiba: “Don't tell me how often it's wrong. Tell me which wrong.”
Watch
Four boxes that tell the truth — — scan code 10.3.3 in the printed book.
Learn it
"Wrong 10 times in 60" hides the question that matters: wrong how? A model can miss what it is looking for, or raise a false alarm, and the two can cost completely different amounts. A confusion matrix sorts every prediction into one of four boxes, so you can see exactly which mistakes a model makes, and put a price on each.
Words to know
- Positive class the thing the model is looking for (here, scab). Choose it first. The other class is negative.
- Confusion matrix a table of actual classes (down the side) against predicted classes (across the top).
- True Positive (TP) really positive, predicted positive.
- False Negative (FN) really positive, predicted negative: a miss.
- False Positive (FP) really negative, predicted positive: a false alarm.
- True Negative (TN) really negative, predicted negative.
- Accuracy from the matrix (TP + TN) ÷ (TP + TN + FP + FN).
Step by step: a confusion matrix for a fever checker
Positive = fever. Results for 50 children:
| Predicted fever | Predicted no fever | |
|---|---|---|
| Actually fever | TP = 4 | FN = 1 |
| Actually no fever | FP = 5 | TN = 40 |
- Check the totals: 4 + 1 + 5 + 40 = 50. The top row (5) is how many children really had fever.
- Accuracy: (4 + 40) ÷ 50 = 88%.
- Read the mistakes: 1 miss (a sick child sent back to class) and 5 false alarms (healthy children sent to the nurse).
- Put a price on each: suppose a false alarm costs 10 minutes of the nurse's time, and a miss means a sick child spreads fever to a whole class. One miss may cost far more than five false alarms.
- Compare models by cost, not just accuracy: a model with more false alarms and no misses may be the better one here.
Rows and columns: each row adds up to how many there really were; each column to how many the model said there were.
Careful: you must say which class is positive. Swap it, and TP becomes TN, FN becomes FP, and every later number changes meaning.
On the laptop
You need: LibreOffice Calc · datasets/leaf-predictions.csv
Mission 1: Build the matrix (12 min, in pairs)
- ☐1
Open
leaf-predictions.csv. Positive class: scab. - ☐2
Somewhere empty, draw this table:
Predicted scab Predicted healthy Actually scab TP FN Actually healthy FP TN - ☐3
Predict: which of the four cells will be biggest? Which smallest? Write both in the cell above the table.
- ☐4
Fill each cell with
COUNTIFS. TP is=COUNTIFS(C2:C61;"scab";D2:D61;"scab"). Work out the other three. - ☐5
Check: all four add to 60. The top row adds to how many leaves were really scab.
Mission 2: Accuracy from the matrix (5 min)
- ☐6
Work out (TP + TN) ÷ 60. It should match Lesson 3.2.
Mission 3: The price of each mistake (8 min)
- ☐7
Hiba's uncle says a miss (FN) costs him about ₹2,000 in spread disease, and a false alarm (FP) about ₹300 of spray. Work out the cost of the model's mistakes.
- ☐8
Build the matrix for Rahat's lazy model from Lesson 3.2, and cost its mistakes the same way.
- ☐9
In the cell under both, finish: "The model with more right answers is … ; the model that costs less is … "
Finished early?
Find the "break-even" price: how cheap would a miss have to be before the lazy model cost less than the real one?
No laptop today?
Twelve leaf cards go round the class: each shows actual and predicted. Four corners of the room are TP, FN, FP and TN. Everyone walks to their corner and the corners count themselves. Then cost the mistakes on the board.
Debate it
The ₹2,000 and ₹300 were the uncle's guesses.
- Who else pays when a miss lets scab spread? (Think about the orchard next door.)
- For a model that screens people for a disease, what would a false negative cost — and could anyone put a rupee figure on it?
Check yourself — practice, not a test
1. Match each case to its cell (positive = scab):
Really scab, predicted scab · Really scab, predicted healthy · Really healthy, predicted scab · Really healthy, predicted healthy
Match with: True Positive · False Negative · True Negative · False Positive2. A false alarm is a:
- ○ True Positive
- ○ False Positive
- ○ False Negative
- ○ True Negative
3. Accuracy from a confusion matrix = (TP + ______) ÷ all predictions.
4. In CBSE's confusion matrix, the actual values run down the side and the predicted values across the top.
- ○ True
- ○ False
5. TP = 11, FN = 4, FP = 6, TN = 39. How many leaves were really scab?
- ○ 11
- ○ 15
- ○ 17
- ○ 50
Remember
Don't ask how often it's wrong. Ask which wrong.
Typing practice
Skill: a count with two conditions (5 min)
-
On typing.com: the symbols lessons.
-
Type three times, eyes on the screen:
=COUNTIFS(C2:C61;"scab";D2:D61;"healthy") -
Goal this term: 38–44 WPM at 95%.