Picking Classification Metrics for an Imbalanced Medical Test
Statistics & ExperimentsModel answerLast updated
Choose and justify evaluation metrics for a rare-disease screening model where false negatives and false positives carry very different costs.
Scenario
You are a data scientist building a binary classifier for a diagnostic lab. The model screens blood samples and predicts whether a patient has a rare condition (Positive) or does not (Negative).
The Data
- Samples processed per day: 500,000
- Positive cases (condition present): 50 (0.01%)
- Negative cases (condition absent): 499,950 (99.99%)
The Business Context
- A false positive (flagging a healthy patient as sick) triggers expensive follow-up testing and causes significant patient anxiety. The cost is real but bounded.
- A false negative (clearing a sick patient as healthy) means the condition goes untreated, with serious health consequences and substantial liability for the lab.
- Internal estimates put the cost of a false negative at roughly 20× the cost of a false positive.
What You Are Asked to Do
- Explain why reporting model accuracy would be misleading here, and name a better metric or combination of metrics for this setting.
- Given the 20:1 cost asymmetry, how would you set the classification threshold (instead of the default 0.5)? Walk through the math, then describe how you would validate that choice before deploying.
- Compare ROC-AUC and Precision-Recall AUC as evaluation curves for this model. Which do you prefer, and why does the class distribution matter for that choice?
For each part, give concrete reasoning — use numbers from the scenario where it helps.
Hints
Hint 1
Start by computing what accuracy a model that predicts 'Negative' for every sample would achieve, then ask what its recall is. That tension is the whole argument against accuracy here.
Hint 2
For the threshold, think of it as a decision between two expected costs. Set them equal and solve for the probability cutoff — the cost ratio is your main input.
Hint 3
ROC-AUC's false-positive-rate axis divides by the number of true negatives. Ask yourself what happens to that denominator when negatives outnumber positives 10,000 to 1.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Strong Answer
What this question is really testing
Three distinct skills: recognizing why accuracy is structurally broken under extreme imbalance, translating a cost ratio into a threshold using first principles, and knowing which evaluation curve actually surfaces meaningful differences when negatives dominate. Numbers matter throughout — vague answers about "preferring recall" do not earn full credit.
Part 1: Why accuracy fails here
Start with the dumbest possible model — one that predicts Negative for every sample:
| Predicted Positive | Predicted Negative | |
|---|---|---|
| Actual Positive (50) | TP = 0 | FN = 50 |
| Actual Negative (499,950) | FP = 0 | TN = 499,950 |
Accuracy = 499,950 / 500,000 = 99.99%. Recall = 0/50 = 0%. This model catches zero cases of the condition and looks nearly perfect by accuracy. No deployable model can beat that accuracy score by more than 0.01 percentage points, so accuracy provides almost no signal about whether the model is useful.
The root cause is that accuracy is dominated by the true-negative count. With 499,950 negatives in the denominator, getting every negative right swamps any improvement in detecting the 50 positives.
Better metrics for this problem:
- Recall (sensitivity): the fraction of sick patients the model actually catches. Because false negatives are the expensive error, this is the primary objective.
- Precision: the fraction of flagged patients who are truly sick. Low precision means flooding the follow-up pipeline with healthy patients.
- F-beta (β = 2 or higher): a single summary score that weights recall more heavily than precision. F2 is a reasonable default given the 20:1 cost ratio.
- Expected business cost:
Cost = C_FP · FP + C_FN · FN. This directly encodes the 20:1 ratio and is the most honest single number you can report to stakeholders. - PR-AUC (Average Precision): a threshold-independent summary of the precision-recall tradeoff, discussed in Part 3.
Part 2: Setting and validating the threshold
Deriving the optimal threshold. Assume the model outputs calibrated probabilities. Let p = P(positive | x), C_FP = 1, C_FN = 20.
Expected cost of flagging the sample: (1 − p) · C_FP
Expected cost of clearing the sample: p · C_FN
Flag when the cost of clearing exceeds the cost of flagging:
p · 20 > (1 − p) · 1
p* = 1 / (1 + 20) = 1/21 ≈ 0.048
The threshold drops from 0.5 to about 0.05. Because missing a positive is so costly, you flag at low confidence — you would rather investigate a healthy patient than miss a sick one.
Sanity-check with a concrete example. Suppose a model with 80% recall and a false-positive rate of 0.1% (500 FPs per day):
- TP = 40, FN = 10, FP = 500, TN ≈ 499,450
- Accuracy ≈ 99.9% — looks great
- Expected cost = 500 · 1 + 10 · 20 = 700 units
- "Do nothing" baseline cost = 50 · 20 = 1,000 units
The model adds value here, but only barely. Dropping FPR to 0.02% (100 FPs) gives cost = 100 + 200 = 300. The "do nothing" comparison is a step candidates often skip — it is essential.
Validation procedure:
- Time-based split. Use earlier time periods for training and later ones for validation. Random splits are optimistic because they leak future patterns into training.
- Bootstrap confidence intervals on cost. With only 50 positives per day, a single day's recall estimate is noisy. Pool several weeks, then bootstrap to put uncertainty bands around cost, recall, and precision.
- Threshold sweep on the validation set. The analytic 1/21 threshold assumes perfectly calibrated probabilities. In practice, re-sample or re-weight training data (which distorts probabilities) and tree-based models are often miscalibrated. Sweep thresholds on held-out data and pick the one minimising total cost directly.
- Shadow mode first. Run the new threshold alongside the current system, log predictions, and compare outcomes before any live impact.
- Monitoring post-deployment. Track score distribution drift, daily alert volume, confirmed positive rate among flagged samples, and recalibration triggers.
Part 3: ROC-AUC vs. PR-AUC
Prefer PR-AUC.
ROC plots recall (TPR) against the false-positive rate (FPR = FP / (FP + TN)). With 499,950 negatives, 500 false positives give FPR = 0.001. That ROC operating point looks essentially perfect (0.001, 0.8), and a model can achieve ROC-AUC > 0.99 while being nearly worthless operationally.
Precision-recall curves ignore true negatives entirely. Precision = TP / (TP + FP), so those same 500 false positives reduce precision to 40/540 ≈ 7.4% — which is exactly the pressure on the follow-up pipeline that stakeholders care about. The PR curve exposes this in a way ROC cannot.
Two additional properties make PR-AUC preferable here:
- The random-classifier baseline for PR equals the prevalence (0.01%), so it is easy to read how much lift the model provides. The ROC baseline is always 0.5 regardless of imbalance.
- Two models with nearly identical ROC-AUC can differ substantially in PR-AUC, because their differences sit in the low-FPR region of the ROC curve — a region that contributes almost nothing to ROC area.
ROC-AUC is still useful for one thing: comparing ranking quality across time periods where prevalence shifts, since ROC is prevalence-invariant. If you report it, restrict to partial AUC over FPR ∈ [0, 0.001] so you focus on the operating region that matters.
Common mistakes to avoid
- Leaving the threshold at 0.5, or moving it in the wrong direction. Higher FN cost means a lower threshold, not a higher one.
- Deriving
p* = 1/21but forgetting it requires calibrated probabilities — any resampling or class weighting during training breaks calibration and requires a correction step. - Calling 99.9% accuracy or 0.99 ROC-AUC "good" without calculating precision or total cost.
- Validating on a random split or a single day with ~50 positives — both produce unreliable recall estimates.
- Skipping the "do nothing" baseline in the cost comparison. A model that scores lower cost than flagging nothing is table stakes, not a success.