The confusion matrix, from scratch
Wrong ten times can cost a farmer ₹3,000 — or ₹20,000. It depends which wrong.
- Build a confusion matrix from raw predictions
- Name TP, FP, TN and FN
- Put a price on each kind of mistake
The confusion matrix, from scratch
Wrong ten times can cost a farmer ₹3,000 — or ₹20,000. It depends which wrong.
- Build a confusion matrix from raw predictions
- Name TP, FP, TN and FN
- Put a price on each kind of mistake
Story
's uncle.
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
the thing the model is looking for (here, scab). Choose it first. The other class is negative.
a table of actual classes (down the side) against predicted classes (across the top).
really positive, predicted positive.
really positive, predicted negative: a miss.
really negative, predicted positive: a false alarm.
really negative, predicted negative.
(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.
Your missions
datasets/leaf-predictions.csvBuild the matrix
12 minin 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.
Only you can see this - 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.
Accuracy from the matrix
5 min- 6
Work out (TP + TN) ÷ 60. It should match Lesson 3.2.
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 … "
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
In the app, students answer these one at a time and each answer is checked straight away. It's practice, never a mark — anything they miss comes back later for another go.
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
- True Positive
- False Negative
- True Negative
- False Positive
2.A false alarm is a:
- ATrue Positive
- BFalse Positive
- CFalse Negative
- DTrue 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.
TrueFalse5.TP = 11, FN = 4, FP = 6, TN = 39. How many leaves were really scab?
- A11
- B15
- C17
- D50
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%.
Written and designed by Faizan Ayoub. © 2026 Faizan Ayoub. All rights reserved.