For a rare event, precision and recall expose false-alert workload and missed cases more directly than accuracy, while precision changes with event prevalence.
Rare-event precision, recall and changing prevalence
Put the confusion counts on the table
A receipt-review model flags suspicious claims. True positives are flagged claims later confirmed suspicious; false positives are flagged routine claims. Precision is true positives divided by all flags. Recall is true positives divided by all confirmed suspicious claims. A model that predicts routine for every claim can post high accuracy when suspicious claims are rare yet have zero recall. The decision-threshold lesson connects scores to analyst workload.
Evaluate the intended threshold and capacity
Ranked probabilities become an action only at a cutoff or top-K capacity. Changing the cutoff moves precision and recall; the best operating point depends on review time and missed-case cost. The code calculates confusion counts for a frozen threshold on labeled holdout claims. It rejects an empty set and reports undefined precision as None when no alerts are sent, rather than silently calling it zero or one.
Watch prevalence move
If the suspicious-claim rate falls while sensitivity and specificity stay similar, a larger share of flags can be false positives. Do not copy a precision number from a high-risk validation set to an ordinary production stream. If validation deliberately oversampled suspicious claims, raw precision from that set is not production precision. Reweight by the target population or evaluate a representative future holdout. Sampling weights explain the design issue.
Do not let one metric settle model choice
Recall near one can be obtained by flagging almost every claim, overwhelming reviewers. Precision near one may come from a tiny alert set that misses most suspicious cases. Report event prevalence, both denominators, alert count, and cost or capacity at the chosen threshold. A precision-recall curve can summarize threshold tradeoffs, but threshold selection still belongs to development data, not final test outcomes.
Separate ranking from probability meaning
A model can rank suspicious claims well while its probabilities are poorly calibrated. If a 0.20 score is used to estimate expected review yield, calibration matters. If the action is simply the top 47 claims each morning, ranking and capacity may dominate. Calibration tests score meaning; the review project keeps classification and regression targets separate.
Implementation
def threshold_counts(labeled_scores, threshold):
if not labeled_scores or not 0 <= threshold <= 1:
raise ValueError("invalid scores or threshold")
true_positive = false_positive = false_negative = true_negative = 0
for suspicious, risk_score in labeled_scores:
if suspicious not in (0, 1) or not 0 <= risk_score <= 1:
raise ValueError("invalid label or risk score")
flagged = risk_score >= threshold
if flagged and suspicious:
true_positive += 1
elif flagged:
false_positive += 1
elif suspicious:
false_negative += 1
else:
true_negative += 1
alerts = true_positive + false_positive
cases = true_positive + false_negative
return {"precision": true_positive / alerts if alerts else None,
"recall": true_positive / cases if cases else None,
"alerts": alerts, "true_positive": true_positive,
"false_positive": false_positive,
"false_negative": false_negative,
"true_negative": true_negative}
claims = [(1, .87), (0, .75), (1, .48), (0, .31), (0, .08)]
review = threshold_counts(claims, .45)
assert review["alerts"] == 3
assert abs(review["precision"] - 2 / 3) < 1e-12
assert review["recall"] == 1Performance and operating cost
For N scored claims, one threshold report is O(N) time and O(1) auxiliary space. Evaluating T thresholds directly is O(N × T); sorting once supports a full precision-recall sweep in O(N log N) time.
Common Mistakes
- Do not use accuracy alone for a rare-event workflow.
- Do not transfer precision from a case-enriched validation set without accounting for prevalence.
- Do not call precision zero when the model sends no alerts.
Read next
- Decision thresholds: choose an action from probabilities and error costs
- Probability calibration: test whether risk scores mean what they say
- Decision-tree splits and minimum leaf support
- Project: review shipment-delay and claim-risk models
Continue the workflow: Logistic regression, log loss and odds.
Continue the workflow: Multiclass confusion and action costs.
Continue the workflow: Weak-label rules, coverage and conflicts.
Continue the workflow: Group error gaps and policy audit.
Continue the workflow: Multi-label metrics and denominators.
Continue the workflow: Evaluate PU models with an adjudicated sample.
