How do we know an algorithm is good?

After training, a model is tested on data it has never seen. For yes/no problems, the results go into a confusion matrix, and from it we calculate accuracy, precision and recall. Which one matters most depends on the cost of each kind of mistake.

Everyday analogy

A security guard at a mall. Precision asks: of the people they stopped, how many were really shoplifters? Recall asks: of all the shoplifters, how many did they catch?

Example

For cancer screening, missing a real case is very costly, so recall matters most. For a spam filter, sending an important email to spam is annoying, so precision matters a lot.

Model says →SpamNot spam✅ True positivespam caught: 90❌ False negativespam missed: 10❌ False positivegood email blocked: 5✅ True negativegood email kept: 895Really spamReally not spam
A confusion matrix shows which mistakes a model makes, not just how often it's right.

A spam filter tested on 100 emails (30 are really spam)

Predicted: spamPredicted: not spam
Really spam25 caught correctly
true positives
5 missed
false negatives
Really not spam3 wrongly flagged
false positives
67 correctly left alone
true negatives
Accuracy 92%Right overall: (25 + 67) ÷ 100
Precision 89%Of the 28 flagged, how many were spam: 25 ÷ 28
Recall 83%Of the 30 spam, how many were caught: 25 ÷ 30
For numbersUse average error, e.g. "off by 4 minutes on average"

Try it yourself

About 15 min

Build a confusion matrix

  1. Use your spam guesses from the Naive Bayes task (or make up 10 predictions with the true answers).
  2. Count true positives, false positives, true negatives and false negatives.
  3. Work out accuracy and decide which mistake is worse for spam.

What you should see: Accuracy alone can mislead; the type of mistake matters.

Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.

Build it for real · guided projectYour first machine learning model: predict house pricesAbout 75 min · Copy-paste code · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.