MODULE 06 · Junior · 90 minutes

99.2% accurate — and it caught zero fraudsters

Fraud is 0.8% of the data. A model that always answers “not fraud” scores 99.2% and catches nobody. We look at what to measure instead of accuracy.

Open this module in the simulator All 23 lessons

The first two modules are free, no card. The rest are $20/month.

🏢 The situation

An intern from a neighboring team brags in the general chat: "Trained an anti-fraud model, 99.2% accuracy!" Igor sends you a DM:

"Look at his notebook and find the catch. Hint: fraud is 0.8% of the data. Then present it at the demo — it's the best lesson on metrics you can get."

You open the notebook: the model always predicts "not fraud". Accuracy = 99.2%, because honest transactions are 99.2%. The model is useless — it didn't catch a single fraudster.

🎯 Your task

  1. Master the confusion matrix and the metrics: precision, recall, F1.
  2. Understand ROC-AUC and PR-AUC.
  3. Learn to choose the metric based on the business cost of errors.

📚 Theory

The confusion matrix

For binary classification (fraud = the positive class):

Predicted: fraud Predicted: not fraud
Actually fraud TP (caught) FN (missed a fraudster)
Actually not fraud FP (blocked an honest user) TN

Two errors — two different damages:

The core metrics

Metric Formula Answers the question
Accuracy (TP+TN)/all "What share of predictions is correct?" — misleading under imbalance
Precision TP/(TP+FP) "Of those flagged as fraud — how many really are?"
Recall TP/(TP+FN) "Of all fraud — how much did we catch?"
F1 harmonic mean of P and R a compromise when both matter

Precision and recall are always in tension: lower the threshold → catch more fraud (recall ↑), but block honest users more often (precision ↓).

Confusion matrix TPcaught the fraud FNmissed! −$$$ FPblocked an honest user TNcorrectly passed predicted: fraud predicted: not fraud actually fraud not fraud ROC curve AUC = 0.83 coin flip: AUC = 0.5 FPR → TPR (recall) →
Left: the four outcomes of classification — FN and FP have different costs. Right: the ROC curve shows quality across all thresholds; the diagonal is random guessing.

ROC-AUC and PR-AUC

How to choose a metric: from the cost of errors

The mature engineer's algorithm:

  1. Write down the cost of an FP and an FN in money/consequences.
  2. Understand the operational constraint (how many cases can the manual review team handle?).
  3. Choose the metric: e.g. "recall at precision ≥ 90%" or "precision within the top-1000 daily alerts".

What to remember

  • Accuracy lies under class imbalance.
  • Precision = alert purity; Recall = catch completeness; they always trade off.
  • ROC-AUC — model comparison; PR-AUC — honesty with a rare class.
  • The threshold is chosen from error costs and operational limits, not "0.5 by default".

Next in this module: Practice

Open the module →

Nearby lessons

05 Customers are leaving: a churn model 07 Credit scoring: data decides everything

The whole program — 23 lessons