Precision-Recall against ROC

The same model on the same scores. Drag the positive rate down and watch ROC stay flattering while the PR curve tells the truth.

Precision-Recall against ROC

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

ROC plots true positive rate against false positive rate. Both are computed within a class, so neither depends on the balance.
That independence is the problem: on imbalanced data ROC looks good for a model that is not useful.
The PR curve uses precision, whose denominator mixes both classes, so it falls when positives are rare.
The no-skill baseline is the diagonal for ROC and a horizontal line at the positive rate for PR.

Overview

Both curves evaluate a classifier across decision thresholds. ROC focuses on rates within each actual class; precision–recall focuses on the correctness and coverage of positive predictions. Class prevalence affects their baselines differently.

In this guide
  1. What the curves measure
  2. A rare-class example
  3. Change prevalence in the visualiser
  4. Which one should you use?

What the curves measure

A classifier often produces a score, such as a probability. Choosing a threshold turns those scores into positive or negative predictions. Each threshold gives a confusion matrix and a point on each curve.

True positive rate (recall) = TP / (TP + FN)

False positive rate = FP / (FP + TN)

Precision = TP / (TP + FP)

The ROC curve plots true positive rate against false positive rate. The precision–recall curve plots precision against recall. ROC AUC summarises ranking across thresholds; average precision summarises precision as recall increases. Neither metric chooses a deployment threshold or checks whether predicted probabilities are calibrated.

A rare-class example

Suppose a test set contains 100 positive cases and 9,900 negatives. At one threshold, a model catches 90 positives (recall 0.90) and incorrectly flags 5% of negatives. That is 495 false positives, so precision is:

90 / (90 + 495) ≈ 0.154

The ROC point is (FPR 0.05, TPR 0.90). If the same rates held in a balanced set with 100 negatives, there would be 5 false positives and precision would be 90 / 95 ≈ 0.947. The true-positive and false-positive rates are unchanged, but the number of false alarms and the precision differ because prevalence changed.

Change prevalence in the visualiser

  1. Set Fraction of rows that are positive near 0.50, then note the ROC and precision–recall curves.
  2. Lower it toward 0.01. The ROC baseline remains 0.5 for random ranking, while the no-skill precision–recall baseline follows the positive-class prevalence. With rare positives, small false-positive rates can still produce many false alarms.

The exact curve shape depends on the scores; the key distinction is how the axes and baselines respond to class balance.

Which one should you use?

QuestionUseful viewWhat to keep in mind
How well does the model rank positives above negatives overall?ROC AUCIt is prevalence-insensitive when the class-conditional score distributions stay fixed, but it does not show the volume of alerts by itself.
How many flagged cases are correct, and how many positives are found?Precision–recallIts baseline changes with prevalence, so compare scores against that baseline and use the intended deployment prevalence.
What threshold should run in production?Neither curve aloneChoose on validation data using the costs or capacity limits of false alarms and misses.

Precision–recall is often more revealing for rare-positive tasks such as fraud review or defect detection. ROC remains useful for ranking and for seeing the false-positive rate directly. Read both in the context of the task, and use threshold tuning to choose an operating point. The scikit-learn evaluation guide documents these metrics; Davis and Goadrich discuss the relationship between ROC and precision–recall spaces in their ICML paper.

Check yourself

0 of 3

Answer without scrolling back up.

  1. Why does ROC stay flattering as positives become rare?

  2. 10,000 rows, 100 positive, 90% recall and 5% false positive rate. What is precision?

  3. What is the no-skill baseline on a PR curve?

Cheat sheet

Precision-Recall against ROC

Draw ROC and precision-recall curves from the same predictions. See why a model that looks strong on ROC can fail on imbalanced classes.

MACHINE LEARNING · vizlearn.in/machine_learning/precision_recall_vs_roc.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.

Teaching a course with this? Individual teachers can use it freely; for a whole department or programme, see institutional licences.