# ROC-AUC vs PR-AUC

> What ROC-AUC and PR-AUC measure, why PR-AUC is safer when positives are rare, and which one to report, explained simply for your AI interview.

**In short:** ROC-AUC scores how well a model ranks positives above negatives across every threshold, but with rare positives a few false alarms at the top can hide behind a high score. PR-AUC scores the precision and recall trade-off instead, so it is the safer guide when positives are rare.

AI and LLM interview question Q421, Classic ML and deep-learning basics. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/roc-auc-vs-pr-auc

## Say it in 30 seconds

ROC-AUC and PR-AUC both grade how well a model ranks its scores across every cut-off. ROC-AUC looks at catches and false alarms, so with rare fraud it can look high even when many of the top alerts are wrong. PR-AUC looks at precision and recall, so it shows that problem. I would report PR-AUC first, check the precision of the top alerts, and use ROC-AUC when the two classes are roughly even.

## Say it in 2 minutes

A classifier gives every payment a score, and the bank picks a cut-off above which a payment is flagged. ROC-AUC and PR-AUC both grade the ranking behind those scores, across every possible cut-off. Each one is a single number from 0 to 1, where higher is better.

ROC-AUC looks at the catch rate and the false alarm rate. The false alarm rate divides by all the honest payments, so with a lot of honest traffic a handful of wrong flags barely move it. That is why a model can get a high ROC-AUC and still be poor at the top of the list.

PR-AUC looks at precision, how many flags are right, and recall, how much fraud you catch. Neither one counts the honest payments that were correctly left alone, so the huge pile of easy rejections cannot hide the problem. When fraud is about one payment in a hundred, I would report PR-AUC first, check the precision of the top alerts, and say which cut-off the team will use.

When the two classes are roughly even, ROC-AUC is a fine summary and easy to compare across models. The Google course says so. It adds that, when the dataset is imbalanced, precision-recall curves may offer a better comparative visualization of model performance.

## What are ROC-AUC and PR-AUC, in plain words?

A classifier gives each payment a score. You pick a threshold, a cut-off score above which a payment is flagged as fraud. Move the cut-off up or down and you catch more fraud, but you also block more honest customers. A curve shows that trade-off at every cut-off. The AUC is the area under that curve, a single number from 0 to 1.

ROC-AUC uses the ROC curve, which plots the share of fraud you catch against the share of honest payments you wrongly flag. PR-AUC uses the precision-recall curve, which plots how many of your flags are right against how much fraud you catch. Both grade the same ranking, but they weigh the mistakes differently.

Think of a hospital triage nurse sorting a waiting room by how urgent each patient looks. The ranking is what she produces, and the hospital decides later where to draw the line. A fraud model works the same way: it ranks payments, and the bank picks the cut-off.

- **Threshold:** The score above which a payment is flagged. Moving it trades catches against false alarms.
- **ROC curve:** A plot of the true positive rate against the false positive rate at every threshold.
- **PR curve:** A plot of precision against recall at every threshold.
- **Area under the curve (AUC):** The area under a curve, from 0 to 1. Higher means the ranking is better.
- **Precision and recall:** Precision is how many flags are right. Recall is how much of the fraud you catch.

## How do the two curves differ?

- **ROC: Two rates.** Catch rate (true positive rate) on one axis, and false alarm rate (false positive rate) on the other.
- **PR: Two qualities of the flags.** Precision, how many flags are right, against recall, how much of the fraud you catch.

The false alarm rate divides your false alarms by all the honest payments. With 990 honest payments, three false alarms are about 0.3 percent of them, a number that looks tiny. Precision and recall never use the honest payments that were correctly left alone, so PR-AUC does not get that cushion.

> "The area under the ROC curve (AUC) represents the probability that the model, if given a randomly chosen positive and negative example, will rank the positive higher than the negative." (Google Machine Learning Crash Course)
>
> "AP summarizes a precision-recall curve as the weighted mean of precisions achieved at each threshold, with the increase in recall from the previous threshold used as the weight" (scikit-learn)

## Why can ROC-AUC look good on rare fraud?

Take 1,000 card payments, 10 of them fraud. Two made-up models score them. Model A ranks most fraud high, but three honest payments score above every fraud. Model B ranks its fraud near the top, except one fraud that slips well down the list.

*Diagram, Rare fraud: two curves, two winners: Same scores, two judges. ROC-AUC divides three false alarms by 990 honest payments and still scores Model A high. PR-AUC looks at the top of the list, where those false alarms sit, and picks Model B.*
1. ROC-AUC reads every payment score.
2. PR-AUC reads the same scores, top of the list first.
3. Model A's three false alarms barely dent ROC-AUC, so it scores 0.997.
4. Model B's fraud sits near the top, so PR-AUC scores it 0.901.

Here is the script. It builds both models and prints both scores.

```python
# A fraud model on 1,000 card payments, 10 of them fraud (made-up numbers).
import random
labels = [1] * 10 + [0] * 990
def roc_auc(scores, labels):
    # Chance a random fraud scores above a random genuine payment.
    pos = [s for s, y in zip(scores, labels) if y]
    neg = [s for s, y in zip(scores, labels) if not y]
    wins = sum((p > n) + 0.5 * (p == n) for p in pos for n in neg)
    return wins / (len(pos) * len(neg))
def pr_auc(scores, labels):
    # Average precision: walk down the ranked list, precision at each fraud found.
    tp, ap = 0, 0.0
    for k, (_, y) in enumerate(sorted(zip(scores, labels), reverse=True), 1):
        if y:
            tp += 1
            ap += tp / k
    return ap / sum(labels)
rng = random.Random(7)
fraud = [0.4 + 0.6 * rng.random() for _ in range(10)]
genuine = [0.3 * rng.random() for _ in range(990)]
# Model A: three genuine payments score above every fraud (false alarms at the top).
a_genuine = [1.5, 1.4, 1.3] + genuine[3:]
# Model B: one fraud slips to a low score, under most genuine payments.
b_fraud = fraud[:-1] + [0.05]
for name, f, g in [("Model A", fraud, a_genuine), ("Model B", b_fraud, genuine)]:
    scores = f + g
    print(f"{name}: ROC-AUC {roc_auc(scores, labels):.3f}, PR-AUC {pr_auc(scores, labels):.3f}")
```

Output:

```text
Model A: ROC-AUC 0.997, PR-AUC 0.596
Model B: ROC-AUC 0.918, PR-AUC 0.901
```

ROC-AUC says Model A is best, at 0.997 against 0.918. PR-AUC says Model B is best, at 0.901 against 0.596. The top of the list is where a fraud team looks, so PR-AUC fits the job. These are made-up numbers from a small script, not a benchmark result.

PR-AUC here is average precision. scikit-learn adds up the precision at each step down the ranked list, weighted by how much recall that step adds. It warns that another method, the trapezoidal rule, joins the points with straight lines, and that this can be too optimistic.

## Which one should you report?

1. **Count the positives first:** If fraud, or any rare event, is a small slice of the data, lead with PR-AUC.
2. **Use ROC-AUC for even classes:** When the classes are roughly balanced, ROC-AUC is a fair summary and easy to compare across models.
3. **Look at the top of the list:** Ask how many of the first 50 alerts are real. That is the number the fraud team lives with.
4. **Name a cut-off:** Pick the threshold that matches the cost of a false alarm, then report precision and recall at that point.

> "AUC and ROC work well for comparing models when the dataset is roughly balanced between classes." (Google Machine Learning Crash Course)
>
> "When the dataset is imbalanced, precision-recall curves (PRCs) and the area under those curves may offer a better comparative visualization of model performance." (Google Machine Learning Crash Course)

> **Tip:** Report both numbers and say which one drove the choice. If someone shows you only ROC-AUC for a one-in-a-hundred problem, ask for the precision of the top alerts.

### How would you explain a high ROC-AUC to a fraud team?

The fraud lead says the new model has a ROC-AUC of 0.99 and wants it switched on for every payment tonight. Fraud is about one payment in a hundred.

- **Better: Ask for the top alerts.** Check how many of the top 100 flags are real fraud before anything goes live, and report PR-AUC beside ROC-AUC.
- **Weaker: Argue about the ROC number.** A high ROC-AUC does not show that the flags a human will actually review are good.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] Both are areas under a curve that grade one ranking across every cut-off.
- [ ] ROC plots catch rate against false alarm rate. PR plots precision against recall.
- [ ] ROC-AUC can look high on rare positives, because false alarms are divided by many honest cases.
- [ ] On rare positives, PR-AUC is the safer report.
- [ ] A named cut-off, since an AUC alone does not make the live decision.
- [ ] Say which metric drove the choice, and why.

**Common traps**

- Trap: "ROC-AUC is always the best metric." Better: It is a fair summary when the classes are balanced. With rare fraud, look at PR-AUC too.
- Trap: "A higher ROC-AUC always means a better model." Better: Only for the ranking across all cut-offs. The team may act only on the top of the list.
- Trap: "PR-AUC is just accuracy on the positive class." Better: No. It is built from precision and recall at every cut-off, so it measures the ranking.

## Can you spot the weak report?

**Spot the gap:** A team reports ROC-AUC 0.98 on a fraud set where 0.5 percent of payments are fraud, and says the model is ready. What check is missing?

A. A bigger training set, to lift the score
B. Precision of the top alerts: how many are real fraud
C. A newer model name in the report
D. Training for longer, to be sure

**Answer:** B. At half a percent fraud, ROC-AUC can stay high while the top alerts are mostly false alarms. Precision on the alerts the team would act on is the check to add, with PR-AUC beside it.

**Quick check:** A fraud model has 1 fraud in every 200 payments. Which metric should the team lead with?

A. ROC-AUC, because it is the most common
B. PR-AUC, because it focuses on the rare fraud class
C. Accuracy, because it is the easiest to explain
D. Training loss, because it is the lowest number

**Answer:** B. With rare fraud, PR-AUC tracks the flags where it matters. Accuracy is high for a model that flags almost nothing, and training loss does not measure the ranking the team uses.

## Can you answer these from memory?

**Flash cards**

- **What does ROC-AUC measure?** How well the model ranks positives above negatives, across every threshold.
- **What axes does a ROC curve use?** True positive rate (catches) against false positive rate (false alarms).
- **What axes does a PR curve use?** Precision (flags that are right) against recall (fraud you catch).
- **Why can ROC-AUC mislead on rare fraud?** False alarms are divided by many honest payments, so a few barely move it.
- **Which one for rare positives?** PR-AUC, usually, with the precision of the top alerts checked too.
- **Does scikit-learn interpolate average precision?** No. It adds the steps up. Straight-line joins (the trapezoidal rule) can be too optimistic.

## Likely follow-up questions

- Q420 Precision, recall and F1? https://designervenkat.online/interview/ai/precision-recall-and-f1
- Q425 How do you handle class imbalance? https://designervenkat.online/interview/ai/how-do-you-handle-class-imbalance
- Q419 MSE vs cross-entropy loss? https://designervenkat.online/interview/ai/mse-vs-cross-entropy-loss
- Q422 Train/validation/test splits? https://designervenkat.online/interview/ai/train-validation-test-splits
- Q423 What is cross-validation? https://designervenkat.online/interview/ai/what-is-cross-validation
- Q424 What is data leakage? https://designervenkat.online/interview/ai/what-is-data-leakage

## Learn it in depth

- [ROC-AUC: judging every threshold](https://designervenkat.online/learn/machine-learning/roc-auc)
- [Precision: is a yes really a yes?](https://designervenkat.online/learn/machine-learning/precision)
