Choose the Right Metric for an Imbalanced Fraud Detector
Machine LearningModel answerLast updated
Decide which evaluation metrics best capture a fraud detection model's real-world performance when only 0.3% of transactions are fraudulent.
Background
You are a machine learning engineer at a payments company. Your team has just trained a binary classifier to flag potentially fraudulent transactions before they are settled. The dataset has the following properties:
- Training set: 10 million transactions, of which ~30,000 are confirmed fraud (0.3% positive rate).
- Business context: A missed fraud (false negative) costs the company roughly $200 on average. Flagging a legitimate transaction (false positive) triggers a manual review that costs $5 and annoys the customer.
- Operational constraint: The review team can handle at most 2,000 flagged transactions per day.
A colleague proposes evaluating the model with accuracy because "it's the most intuitive metric." Another colleague argues for AUC-ROC alone.
What you are expected to do
- Explain why accuracy is a poor choice here and quantify the problem.
- Explain the limitation of AUC-ROC in this context.
- Identify two or three metrics that are actually appropriate, explaining what each captures and why it fits the business constraints.
- Describe how you would use a precision-recall curve to pick the operating threshold, given the cost asymmetry and the capacity constraint.
- Mention at least one common mistake practitioners make when evaluating models on imbalanced data.
Hints
Hint 1
What accuracy score would a model that predicts 'not fraud' for every transaction achieve? Is that useful?
Hint 2
Think about what the review team capacity constraint implies for the maximum acceptable false-positive rate at your chosen threshold.
Hint 3
AUC-ROC averages performance over all thresholds and all class ratios — what does that hide when the positive class is rare?
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Why Accuracy Fails Here
A naive classifier that always predicts "not fraud" achieves:
Accuracy = 9,970,000 / 10,000,000 = 99.7%
This looks excellent, yet it catches zero fraud cases. Accuracy is dominated by the majority class whenever the class ratio is extreme. With 0.3% positives, even a 99% accurate model could be missing nearly all fraud. Accuracy gives no signal about the minority class and should be discarded as a primary metric.
2. The Limitation of AUC-ROC
AUC-ROC measures the probability that the model ranks a random positive higher than a random negative, averaged across all possible thresholds. The problem:
- The ROC curve plots True Positive Rate vs. False Positive Rate. With 9.97 million negatives, even a very small FPR (say 0.1%) translates to ~10,000 false positives per day — far above the review team's capacity of 2,000.
- Because FPR is computed relative to the huge negative class, AUC-ROC can look great (e.g., 0.97) while the model produces operationally unworkable false-positive volumes at any useful recall level.
- AUC-ROC is insensitive to class imbalance; it treats all threshold operating points equally, masking poor performance in the high-precision, low-recall region that actually matters here.
3. Metrics That Actually Fit
a) Precision and Recall (at the operating threshold)
- Precision = TP / (TP + FP): of all flagged transactions, what fraction are truly fraud? Maps directly to review cost efficiency.
- Recall = TP / (TP + FN): of all actual fraud, what fraction do we catch? Maps directly to fraud dollar loss avoided.
Given the cost asymmetry ($200 missed fraud vs. $5 false-positive review), you may accept lower precision to gain recall, but the capacity constraint caps total flags at 2,000/day.
b) Area Under the Precision-Recall Curve (AUC-PR)
AUC-PR summarizes model quality across thresholds in the space that matters for imbalanced problems. A random classifier achieves AUC-PR ≈ 0.003 (the base rate), so meaningful improvement is easy to see. Prefer this over AUC-ROC as the headline model-comparison metric.
c) Expected Cost (or Net Savings)
Combine the cost structure into a single scalar:
Expected daily cost = FN × $200 + FP × $5
At a given threshold, compute this directly on a held-out day's worth of data. This is the most business-aligned metric and should drive final threshold selection.
4. Using the Precision-Recall Curve to Set the Threshold
Step 1 — Plot the PR curve on a held-out validation set. Each point corresponds to one decision threshold.
Step 2 — Apply the capacity constraint first. The review team handles 2,000 flags/day. On a day with ~30,000 transactions (10M / 365 ≈ 27,400), that cap means:
Max flags = 2,000 → TP + FP ≤ 2,000
Discard all threshold operating points that produce more than 2,000 total flags.
Step 3 — Among feasible points, minimize expected cost. For each remaining point read (Precision, Recall, total flags = TP + FP):
FP = total_flags × (1 - Precision)
FN = total_daily_fraud - TP ≈ ~82 fraud/day × (1 - Recall)
Cost = FN × 200 + FP × 5
Pick the threshold that minimizes this cost. In practice this often lands at moderate-to-high recall (catching 60–80% of fraud) with precision around 3–8% — which sounds low but is fine given the cost ratio.
Step 4 — Sanity check on a time-held-out test set (not just a random split) to guard against temporal leakage.
5. Common Mistakes
Reporting a single threshold's metrics without stating the threshold. Precision and recall without the threshold are meaningless for comparison — a model can trivially improve recall by flagging everything. Always report the threshold alongside the metric, or compare PR curves directly.
Using random train/test splits for fraud data. Fraud patterns drift over time; a random split leaks future information into training, inflating all metrics. Always split chronologically.
Optimizing F1 blindly. F1 weights precision and recall equally. Given that a false negative costs 40× more than a false positive here ($200 vs. $5), the correct generalization is F-beta with β² = 200/5 = 40, heavily penalizing missed fraud:
F_beta = (1 + β²) × (Precision × Recall) / (β² × Precision + Recall)
Most practitioners forget to tune β to the actual cost ratio.
Summary
| Metric | Role |
|---|---|
| Accuracy | Reject — misleading under imbalance |
| AUC-ROC | Supplementary only — hides high-FP region |
| AUC-PR | Primary model comparison metric |
| Precision / Recall at threshold | Operational monitoring |
| Expected daily cost | Final threshold selection |
The core principle: choose metrics that reflect the cost of each error type and the operational constraints of your system, not metrics that are easy to explain in isolation.