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.
A spam filter tested on 100 emails (30 are really spam)
| Predicted: spam | Predicted: not spam | |
|---|---|---|
| Really spam | 25 caught correctly true positives | 5 missed false negatives |
| Really not spam | 3 wrongly flagged false positives | 67 correctly left alone true negatives |
Try it yourself
About 15 minBuild a confusion matrix
- Use your spam guesses from the Naive Bayes task (or make up 10 predictions with the true answers).
- Count true positives, false positives, true negatives and false negatives.
- 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.