Lesson 17 — Confusion counts
Beyond accuracy: the four outcome types
For a yes/no classifier every prediction is one of four kinds. TP (true positive): said yes, was yes. FP (false positive): said yes, was no — a false alarm. FN (false negative): said no, was yes — a miss. TN (true negative): said no, was no. From them come precision = TP / (TP + FP), "how many alarms were real", and recall = TP / (TP + FN), "how many real cases we caught".
tp = sum(1 for p, y in zip(preds, labels) if p == 1 and y == 1)
Why it matters: for a medical test, a miss (FN) is far worse than a false alarm — these counts make that visible where accuracy hides it.
Count fp, fn and tn the same way tp is counted. Precision and recall are then computed for you.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based AI / ML Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for AI / ML Foundations books — check the publication year so the examples match current versions.
Search Amazon →