2.6.8 · D2Model Evaluation & Selection

Visual walkthrough — Precision-recall tradeoff and curves

1,813 words8 min readBack to topic

This page rebuilds the whole precision-recall tradeoff from nothing but a pile of scores and a sliding line. No formula appears before you can see it. By the end you will have drawn the PR curve with your own eyes.


Step 1 — Lay the predictions on a number line

WHAT. A classifier does not shout "fraud!" or "safe!" directly. It hands you a score between and — think of it as a "how suspicious?" dial. We place every transaction on a horizontal line at its score.

WHY. Before we can talk about precision or recall, we need the raw material: scores, plus the truth about each item (was it really fraud?). Colouring each dot by its true label lets us see the mixing that makes the problem hard.

PICTURE. Below, each dot is one item. Its horizontal position is its score . Its colour is the ground truth: red = actually positive (fraud), blue = actually negative (safe). Notice the reds cluster toward the right (high score) but not perfectly — a blue sneaks in among them. That imperfect mixing is the entire reason a tradeoff exists.


Step 2 — Drop the threshold line and read off four counts

WHAT. Pick a threshold (a value on the same line). Draw a vertical line there. Everything on or right of it we call positive; everything left we call negative. Now compare our call to the truth.

WHY. "Positive" and "negative" are not properties of an item — they are our decisions, born the instant we choose . To measure how good those decisions are we cross-tabulate call-vs-truth into four buckets.

PICTURE. The yellow line is . The four regions are the four cells of the confusion matrix:

  • (true positive) — red dot we correctly caught (right of ).
  • (false positive) — blue dot we falsely flagged (right of ) — a false alarm.
  • (false negative) — red dot we missed (left of ) — a miss.
  • (true negative) — blue dot correctly left alone (left of ).
Recall

Which two counts live to the RIGHT of the threshold? ::: (red) and (blue) — everything we called positive.


Step 3 — Define precision and recall right on the picture

WHAT. Two questions about our positive calls, each a simple ratio of the counts from Step 2.

WHY these two ratios and not others? We want to score decisions with two independent worries:

  • Worry 1 — "when I raise the alarm, am I right?" This ignores the huge pile of correctly-ignored blues (); it only cares about the column of things I flagged.
  • Worry 2 — "of the truly bad items, how many did I actually catch?" This ignores false alarms; it only cares about the reds.

  • Precision — the fraction of the right-of-line region that is red. Denominator = all dots I flagged.
  • Recall — the fraction of all red dots that landed right of the line. Denominator = every red, wherever it sits.

PICTURE. Same dots, two shaded frames: the precision frame boxes the right side (mixed red+blue), the recall frame boxes all reds. The overlap — reds inside the right box — is , the numerator both share.


Step 4 — Slide the line LEFT and watch the tug-of-war

WHAT. Move to a smaller value. More dots fall to the right, so we call more things positive.

WHY. This is the experiment. We are forcing the tradeoff to reveal itself by changing exactly one knob and reading both metrics.

PICTURE. Two snapshots side by side. Moving left:

  • Some red that was in (missed) crosses over into recall rises (we caught more of all reds).
  • But some blue also crosses from into → precision's denominator grows → precision usually falls.

Using the parent's fraud data (4 frauds among 10), sweeping :

flagged Precision Recall
{1,2} 2 0 2
{1,2,3,4} 3 1 1
{1..8} 4 4 0

As recall climbs , precision slides . The tug-of-war is visible.


Step 5 — Plot every threshold: the PR curve is born

WHAT. Each threshold gives one pair. Plot recall on the x-axis, precision on the y-axis, one point per threshold, and connect them.

WHY. A single threshold is one opinion. The curve shows all opinions at once, so you can pick the operating point your problem demands (a hospital wants high recall; a spam filter wants high precision).

PICTURE. The three pairs from Step 4 become three dots that trace a downhill path from top-left (high precision, low recall) to bottom-right (high recall, low precision).


Step 6 — Summarise the curve with one number: AUC-PR

WHAT. The area under the PR curve. We add up trapezoids under the connected points.

WHY a trapezoid? Between two known points the curve is unknown, so we approximate that sliver as a straight-topped trapezoid — the cheapest honest guess of the area beneath a slanted segment.

  • — average of the two precisions = the trapezoid's mean height.
  • — the recall gap = the trapezoid's width.

PICTURE. We reuse the exact three points from Step 4's table, sorted by increasing recall: . The shaded trapezoids sit under the segments joining them:

So for our fraud example the trapezoidal AUC-PR .


Step 7 — The degenerate cases you must know

WHAT. The corners of the plot, where counts hit zero.

WHY. A reader who never sees these will misread real curves. Every edge has a meaning.

PICTURE. Four flagged corners on one plot:

  1. (line at far right) — we flag nothing. , so precision is undefined (by convention treated as or dropped); recall . Top-left corner.
  2. (line at far left) — we flag everything. Recall (caught all reds); precision = the positive fraction. Right edge.
  3. No-skill baseline — a coin-flip classifier has expected precision equal to that same positive fraction at every recall → a flat horizontal line. On imbalanced data this baseline is low (e.g. for 2% fraud), so AUC-PR is a 7.5× lift, not "barely better than random".
  4. Perfect classifier — all reds score above all blues → precision stays until recall → curve hugs the top → AUC-PR .

The one-picture summary

Everything on one canvas: the sliding threshold (bottom), the four counts it creates (middle), and the PR curve those counts trace (top) — with the baseline line and AUC-PR shading.

Recall Feynman retelling

I lined up every transaction by how suspicious the model thought it was — reds are truly bad, blues are truly fine. Then I dropped a vertical line and said "anything to the right, I'm calling bad." That instantly splits the world into four piles: caught-reds (), false-alarm-blues (), missed-reds (), and safely-ignored-blues ().

Precision asks "of the stuff I flagged, how much was truly bad?" — the reds among the right pile. Recall asks "of all the truly-bad stuff, how much did I catch?" — reds on the right out of all reds. They share the same top number () but have different bottoms, so when I slide the line left, recall must rise while precision usually sags — that's the tug-of-war.

Each line position gives one (recall, precision) dot; sweeping the line traces the whole curve. The area under it (adding trapezoids) is one score for the model — but I compare it to the fraction of reds in the data (), never to , because a lazy classifier on rare events already scores that fraction for free.