الانتقال إلى المحتوى
Machine Learningتقييم الموديلات· 6 دقائق للقراءة

ROC AUC Can Look Great on Rare Positives: When to Use Precision-Recall Curves

ROC AUC barely notices how rare the positives are, so it can't tell you how many false alarms come with each catch. Precision can.

ReadIn

مقال كل يوم يفرق معاك

22 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

A payments team presents its fraud model at the launch review: ROC AUC 0.933, fraud at 1% of transactions. Operations sets the cut-off to catch 80% of fraud, and within a week the review queue is unmanageable: 91 of every 100 alerts are legitimate customers. Then someone scores the same model on a test set rebalanced to 50% fraud. ROC AUC 0.929, and precision at 80% recall is 0.90. The model didn't change. The number of negatives did, and ROC AUC barely noticed.

The common misconception

Many developers treat ROC AUC as the best single metric for any classifier, heavily imbalanced problems included. It's an easy belief to hold:

  • It needs no threshold and has an elegant meaning. Google's Machine Learning Crash Course describes it as the probability that the model ranks a random positive above a random negative.
  • Chance is always 0.5, whatever the class balance, so a 0.93 always sounds excellent.
  • It doesn't move with the positive rate, which makes scores comparable across datasets. That really is a strength.

The half-truth: honestly measures how well the model orders cases. But the property that makes it stable across class balances also makes it blind to the thing rare positives create: a flood of false alarms.

What actually happens

Both curves come from sweeping the threshold over the model's scores. They differ in what they divide by.

ROC divides by the negatives, precision by the alarms

The ROC curve plots the true positive rate against the false positive rate: false positives divided by all negatives. When negatives outnumber positives 99 to 1, a small false positive rate is a large number of false alarms. Saito and Rehmsmeier show it with one ROC point: 500 true positives and a false positive rate of 0.16 means 160 false positives with 1,000 negatives and 1,600 with 10,000. The ROC point is identical; falls from three alarms in four being right to fewer than one in four. Precision divides by everything the model flagged, so it measures exactly what the review queue feels. Their simulations found that only the precision-recall curve changes with the ratio of positives to negatives.

Same model, same scores, different class mix

The script trains one model on data with 1% fraud, then scores its test set twice: as it is, and with negatives dropped at random until fraud is half the rows. Each row keeps its score; only the mix changes.

Python
from sklearn.datasets import make_classificationfrom sklearn.ensemble import HistGradientBoostingClassifierfrom sklearn.metrics import roc_auc_scorefrom sklearn.model_selection import train_test_splitX, y = make_classification(n_samples=100_000, n_features=20, n_informative=6,                           weights=[0.99], flip_y=0, class_sep=1.0,                           random_state=0)  # 1% of transactions are fraudX_tr, X_te, y_tr, y_te = train_test_split(X, y, stratify=y, random_state=0)model = HistGradientBoostingClassifier(random_state=0).fit(X_tr, y_tr)score = model.predict_proba(X_te)[:, 1]print(f"ROC AUC {roc_auc_score(y_te, score):.3f}")# ROC AUC 0.933

ROC AUC barely moves, 0.933 against 0.929, because both rates it plots are computed within a class. Average precision falls from 0.939 to 0.494, and precision at 80% from 0.90 to 0.09. At the real fraud rate, catching 80% of fraud means more than 10 alerts for each real case. That's the number operations lives with, and ROC AUC can't show it.

Read average precision against its baseline

summarizes the precision-recall curve, and scikit-learn's guide notes that a random ranking scores the fraction of positives. Here that's 1%, so 0.494 is roughly fifty times chance: a strong model on a hard problem, not a weak one. It's also why AP is only comparable between models on the same test set. Google's Crash Course says ROC AUC works well for comparing models when classes are roughly balanced, and that precision-recall curves may compare them better when they aren't. One detail: compute it with average_precision_score, not auc on the curve's points. The guide warns that the linear interpolation auc uses is overly optimistic for precision-recall curves.

When ROC AUC is still the right tool

Precision-recall isn't automatically better under imbalance. McDermott and colleagues show that ROC AUC improves by the same amount whichever mistake you fix, while the precision-recall area rewards fixes among high-scoring cases more. They recommend ROC AUC for context-independent evaluation and when false negatives are especially costly, and the precision-recall area for prioritizing a costly intervention or for retrieval, where high-scoring false positives are the expensive mistakes. They also warn that the precision-recall area can favor subgroups with more positives.

QuestionBest answered by
How well does the model rank, whatever the class mix?ROC AUC
How clean is the top of the list at our real positive rate?Average precision, precision-recall curve
How many alerts per real case at the recall we need?Precision at that recall
Comparing models across datasets with different positive ratesROC AUC, since AP's baseline moves
Every missed positive matters, wherever it ranksROC AUC, plus recall at the chosen cut-off

How to apply it in your project

  1. Write down the real positive rateMeasure it from recent production data; every precision number depends on it.
  2. Plot both curvesUse RocCurveDisplay and PrecisionRecallDisplay with plot_chance_level=True, so each curve shows its own baseline.
  3. Report AP next to ROC AUCGive average precision with its chance level, the positive rate, alongside ROC AUC.
  4. Fix the operating pointState the recall you need, or the queue you can staff, and report the precision there.
  5. Test on the production mixKeep the test set's class balance as it is in production.

Key takeaways

  • ROC AUC divides false positives by all negatives, so it barely reacts to how rare positives are.
  • The same scores gave ROC AUC 0.933 and 0.929, but precision at 80% recall of 0.09 and 0.90.
  • Average precision's chance level is the positive rate; read it against that, on the real class mix.
  • Use ROC AUC for prevalence-free ranking and precision-recall when you act on the top of the list.

📚 المصادر

  1. Classification: ROC and AUC — Google Machine Learning Crash Course
  2. Saito and Rehmsmeier, The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets (PLOS ONE, 2015)
  3. McDermott et al., A Closer Look at AUROC and AUPRC under Class Imbalance (2024)
  4. Precision-Recall — scikit-learn examples
  5. Metrics and scoring: quantifying the quality of predictions — scikit-learn User Guide

التعليقات (0)