BeginnerCoder

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.

Want it another way?
Task

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.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with AI / ML Foundations

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.