g↗genai/ learner
Data and Evaluation / Lesson 08

Accuracy, precision and recall

A score can look strong while hiding the errors that matter. Read the counts first, then choose a measure that fits the cost of mistakes.

Concept + interactive labBeginner friendly

Accuracy can hide a missed case.

Accuracy is the share of all predictions that match what actually happened. It answers “how many were right overall?” but does not show which kinds of mistakes occurred.

We will follow one invented example through the lesson: Northgate Bank tests a card-fraud screener on 20 transactions. Five are actually fraud and 15 are legitimate. Here, fraud is the positive class (the outcome we want to find); legitimate is the negative class.

Worked example: the “flag nothing” baseline

If the screener calls every transaction legitimate, it gets 15 of 20 right: 75% accuracy. Yet it catches none of the five frauds. A smoke alarm that stays quiet on ordinary days can still fail its purpose if it misses a fire.

This is why accuracy alone is not enough when one class is uncommon or when the cost of each error differs. The next step is to inspect the counts behind the score.

Accuracy: 15 correct of 20 total gives 75%; 5 fraud missed. Analogy: Quiet days can hide a missed fire. Key takeaways: ✓ Overall score counts every case; ✓ Rare cases can be hidden; ✓ Check which errors occurred.
The baseline is correct on 15 ordinary transactions, yet misses all five fraud cases.

A confusion matrix separates four outcomes.

A confusion matrix is a 2-by-2 table that compares actual outcomes with the screener’s predictions. Its rows show what actually happened; its columns show whether the screener flagged or allowed a transaction.

A true positive is fraud correctly flagged. A false negative is fraud allowed by mistake. A false positive is a legitimate transaction wrongly flagged. A true negative is a legitimate transaction correctly allowed.

In the lab, these four outcomes are shortened to TP, FN, FP, and TN.

Worked example: Northgate at its current cutoff

On the same 20 transactions, the screener catches 4 frauds, misses 1, flags 3 legitimate purchases, and allows 12 legitimate ones. So it gets 16 of 20 right (80% accuracy), with both kinds of error visible in the counts.

In an everyday smoke-alarm analogy, a real fire that triggers the alarm is a true positive; burnt toast that triggers it is a false positive. A fire with no alarm is a false negative, while clear air with no alarm is a true negative.

Confusion matrix: Actual: Fraud and Actual: Legitimate rows meet Predicted: Flagged and Predicted: Allowed columns. The cells are True positive (4 caught), False negative (1 missed), False positive (3 false alarms), and True negative (12 cleared). Analogy: A smoke alarm catches smoke. Key takeaways: ✓ Rows show what happened; ✓ Columns show the prediction; ✓ Errors have different costs.
The rows are actual outcomes; the columns are the screener’s predictions.

Precision and recall answer different questions.

Precision asks: of everything the screener flagged, what share was really fraud? Its formula is true positives divided by all predicted positives: TP / (TP + FP).

Recall asks: of all the fraud that was actually present, what share did the screener flag? Its formula is true positives divided by all actual positives: TP / (TP + FN).

Worked example: same four catches, different denominators

Northgate flagged 7 transactions; 4 were fraud, so precision is 4 / 7, about 57%. There were 5 actual frauds; 4 were caught, so recall is 4 / 5, or 80%. Precision checks the alerts; recall checks how many real cases were found.

Imagine a net: precision is about how many of the things in the net are the fish you wanted; recall is about how many of those fish in the water the net caught. The analogy helps separate the denominators, but real screening decisions need evidence about actual costs.

Precision and Recall comparison: Precision looks Among flagged with 4 caught of 7 flagged for 57%; Recall looks Among actual fraud with 4 caught of 5 actual for 80%. Analogy: A net gathers fish. Key takeaways: Precision checks alerts; Recall checks cases found; Both count caught cases.
Both measures count the same four caught frauds, but use different groups as their denominator.

Move the cutoff and see what changes.

A risk score is a number the screener assigns to an item; in this toy example, higher scores mean “more suspicious.” A decision threshold is the cutoff used to turn that score into an action: at or above it is flagged, and below it is allowed. These invented scores are not calibrated probabilities.

Before you try it

At cutoff 50, four of five frauds are flagged and three legitimate transactions are false alarms. Lowering the cutoff can catch more fraud while adding alerts; raising it can reduce alerts while missing more fraud.

  1. Start at 50 and compare the three measures and four counts.
  2. Choose 30 and observe what happens to recall and precision.
  3. Choose 70, then 90, and compare the missed cases and alerts.
  4. Use Reset threshold to return to the starting point.
Northgate Bank threshold simulator (20 scored items)
Cutoff: 50
Quick presets
Accuracy
80%
16 / 20 right overall
Precision
57%
4 / 7 flagged are fraud
Recall
80%
4 / 5 actual fraud caught
Actual \ PredictedPredicted: Fraud (Flagged)Predicted: Legitimate (Allowed)
Actual: Fraud (5)4True Positive (caught)1False Negative (missed)
Actual: Legitimate (15)3False Positive (false alarm)12True Negative (cleared)
At threshold 50: Middle threshold: balances catching most fraud against keeping false alarms moderate.
All 20 transactions (sorted by invented risk score)
  • #01 Overseas electronicsScore 92 · Actual: FraudTP · Caught
  • #02 Late-night gift cardsScore 84 · Actual: FraudTP · Caught
  • #03 First hotel abroadScore 78 · Actual: LegitimateFP · False alarm
  • #04 Rapid fuel chargesScore 73 · Actual: FraudTP · Caught
  • #05 New laptop orderScore 64 · Actual: LegitimateFP · False alarm
  • #06 Midnight wallet top-upScore 58 · Actual: FraudTP · Caught
  • #07 Airline seat upgradeScore 52 · Actual: LegitimateFP · False alarm
  • #08 Four concert ticketsScore 47 · Actual: LegitimateTN · Cleared
  • #09 Appliance repairScore 41 · Actual: LegitimateTN · Cleared
  • #10 Small online test chargeScore 36 · Actual: FraudFN · Missed
  • #11 Hardware checkoutScore 33 · Actual: LegitimateTN · Cleared
  • #12 Weekend train passScore 28 · Actual: LegitimateTN · Cleared
  • #13 Pharmacy pickupScore 25 · Actual: LegitimateTN · Cleared
  • #14 Local bookstoreScore 22 · Actual: LegitimateTN · Cleared
  • #15 Weekly groceriesScore 19 · Actual: LegitimateTN · Cleared
  • #16 Streaming renewalScore 16 · Actual: LegitimateTN · Cleared
  • #17 Corner coffee shopScore 14 · Actual: LegitimateTN · Cleared
  • #18 City bus fareScore 11 · Actual: LegitimateTN · Cleared
  • #19 Morning bakeryScore 8 · Actual: LegitimateTN · Cleared
  • #20 Parking meterScore 5 · Actual: LegitimateTN · Cleared

Illustrative simulation: these 20 transactions and their 0–100 risk scores are invented for this lesson. The score reflects how suspicious this toy model treats each item and is not necessarily a calibrated probability.

Choose the measure that fits the error cost.

A false alarm can waste a person’s time or block a legitimate action. A missed case can let a real problem pass. Which matters more depends on the task.

  • If a false alarm is especially costly, inspect precision: for example, a spam filter should avoid hiding important mail.
  • If missing a real case is especially costly, inspect recall: a safety screen may need to catch most hazards for follow-up review.
  • If both error types matter, consider precision and recall together. The F1 score combines both into one number, but can hide which one is weaker.

A validation set is data used to choose settings such as the threshold. A separate test set is held back for a final evaluation. Choose the threshold on validation data, then report its result on the test data; repeatedly tuning to test results can make that final score less informative.

Could recall be high while precision is low?

Yes. Flagging every transaction would find all five frauds in this batch, but it would also create many false alarms.

Could precision be high while recall is low?

Yes. Flagging only one very suspicious fraud could make every alert correct while missing the other four.

✎ Try it yourselfKnowledge check · Practice only

Check your understanding.

A fictional airport screener checks 1,000 bags, including about 10 with forbidden batteries. A missed battery could cause a cargo fire; a flagged bag gets a brief manual check. Which measure best matches the larger cost?

Take this with you.

Accuracy summarizes overall correctness. A confusion matrix shows what kinds of predictions were right or wrong. Precision checks flagged cases; recall checks actual cases found. Choose a measure and threshold based on the cost of each mistake.

Ready to continue? Return to Data and Evaluation.