ML4: Evaluation you can trust

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

The confusion matrix, precision and recall

🎯You'll be able to

Build a confusion matrix, compute precision and recall, and explain them in terms of the people affected.

🏠The everyday picture

A fishing net that catches every fish also catches plastic and weeds. A net with fine selection catches only fish but lets many escape. Recall is "how many of the fish did we catch?"; precision is "how much of the catch is fish?".

📘What it really is

📝A worked example

Input: the kit's model on June at threshold 0.3 (reference figures, 2 November 2026).

from sklearn.metrics import confusion_matrix
tn, fp, fn, tp = confusion_matrix(y_june, p_june >= 0.3).ravel()

Expected output: TN 1,948, FP 58, FN 100, TP 115. So recall = 115 ÷ 215 = 0.5349 and precision = 115 ÷ 173 = 0.6647. In words: the hub makes 173 calls, about two in three reach a customer whose parcel would have been late, and about half of all late parcels are caught.

🌍Where it's used

📝Case scenario

A city's model flagged buildings for fire inspection. Inspectors complained that most visits found nothing: precision was low. Raising the threshold cut wasted visits, but the fire service noticed recall fell too, so a few risky buildings were no longer visited. They agreed a minimum recall first, then raised precision as far as possible within it, which is the rule the kit uses.

🖱️Try it

Compute the confusion matrix for threshold 0.15 on June. Success: TP 142, FP 100, FN 73, TN 1,906, giving recall about 0.66 and precision about 0.59.

⚠️Common mistakes

🛠️For your project

Project 1 reports precision, recall and the number flagged, at the chosen threshold, for May, June and each destination zone.

✅Quick check

What is recall in DakDost's terms?

Show the answer

The share of late parcels that the model flagged.

What does a false positive cost DakDost?

Show the answer

An unnecessary phone call to a customer whose parcel would have been on time.

← PreviousAccuracy and why it misleads
ProLearners Assist