Speed

Precision and Recall at Five Sixths

Compute precision 2/2 = 1.00 and recall 2/4 = 0.50 at cutoff 5/6 and trace the trade-off against cutoff 1/2.

The problem

At Threshold Five Sixths Counts, tightening the rule to sixths = 5 (5 / 6 ≈ 0.8333) produced [TP, FP, FN, TN] = [2, 0, 2, 5]. Notice that TP dropped from 3 at 1 / 2 down to 2 at 5 / 6—so how can precision reach a perfect 1.00 when fewer positives were caught?

Using the fixed nine rows [0.95, 1], [0.90, 1], [0.75, 1], [0.70, 0], [0.60, 0], [0.40, 1], [0.30, 0], [0.15, 0], and [0.10, 0], we compute [precision, recall] at sixths = 5 and compare both fractions against sixths = 3.

Work through the numbers

Substitute TP = 2, FP = 0, and FN = 2 into the two definitions:

  • Precision at 5 / 6: TP / (TP + FP) = 2 / (2 + 0) = 2 / 2 = 1.00. Even though the numerator fell by one (3 -> 2), the denominator shrank by three (5 -> 2) because both false positives (0.70, 0.60) vanished.
  • Recall at 5 / 6: TP / (TP + FN) = 2 / (2 + 2) = 2 / 4 = 0.50. Because recall's denominator stays anchored at 4, losing row 2 (0.75) cuts recall directly by 1 / 4, from 0.75 down to 0.50.

Compare the full shift from 3 / 6 ([0.60, 0.75]) to 5 / 6 ([1.00, 0.50]): precision gained +0.40 while recall gave up -0.25.

The live model

Side-by-side bars display active precision and recall alongside their signed shifts relative to the 3 / 6 baseline [0.60, 0.75]. Slide sixths from 1 to 5: at sixths = 5, precision fills the entire [0, 1] track (+0.40 vs 3 / 6) while recall stops halfway (-0.25 vs 3 / 6).

At cutoff 5/6, precision reaches 1 (+0.4 vs 3/6) while recall drops to 0.5 (-0.25 vs 3/6).
let sixths = scene.parameter("sixths", 5.0, 1.0, 5.0, 1.0);
let cutoff = sixths / 6.0;
let prob = input.select(1, 0);
let label = input.select(1, 1);
let neg_label = label.rsub(1.0);
let p3 = prob.gt(0.5).to(DType.F64);
let tp3 = (p3 * label).sum();
let pr3 = tp3.div(tp3 + (p3 * neg_label).sum());
let rc3 = tp3.div(label.sum());
let b_list = torch.list().add(pr3.reshape(1)).add(rc3.reshape(1));
let base_pr = torch.cat(b_list, 0);
let pred = prob.gt(cutoff).to(DType.F64);
let neg_pred = pred.rsub(1.0);
let tp = (pred * label).sum();
let fp = (pred * neg_label).sum();
let miss_pos = (neg_pred * label).sum();
let precision = tp.div(tp + fp);
let recall = tp.div(tp + miss_pos);
let pr_list = torch.list().add(precision.reshape(1)).add(recall.reshape(1));
let answer = torch.cat(pr_list, 0);
out.set("base_half", base_pr).set("pr_five_sixths", answer);
{
  "base_half": [
    0.6,
    0.75
  ],
  "pr_five_sixths": [
    1,
    0.5
  ]
}
Watch the parameter change

Your turn

Compute [precision, recall] under prob > sixths / 6.0. The starter divides tp by tp + fp + miss_pos (the Jaccard union of positive events) instead of tp + fp for precision, reporting 2 / 4 = 0.50 instead of 1.00 at 5 / 6. Check grades unseen score tables across alternate sixths settings.

Starter model includes missed positives in precision denominator, reporting 0.5 instead of 1.0 at cutoff 5/6.
let sixths = scene.parameter("sixths", 5.0, 1.0, 5.0, 1.0);
let cutoff = sixths / 6.0;
let prob = input.select(1, 0);
let label = input.select(1, 1);
let neg_label = label.rsub(1.0);
let p3 = prob.gt(0.5).to(DType.F64);
let tp3 = (p3 * label).sum();
let pr3 = tp3.div(tp3 + (p3 * neg_label).sum());
let rc3 = tp3.div(label.sum());
let b_list = torch.list().add(pr3.reshape(1)).add(rc3.reshape(1));
let base_pr = torch.cat(b_list, 0);
let pred = prob.gt(cutoff).to(DType.F64);
let neg_pred = pred.rsub(1.0);
let tp = (pred * label).sum();
let fp = (pred * neg_label).sum();
let miss_pos = (neg_pred * label).sum();
let precision = tp.div(tp + fp + miss_pos);
let recall = tp.div(tp + miss_pos);
let pr_list = torch.list().add(precision.reshape(1)).add(recall.reshape(1));
let answer = torch.cat(pr_list, 0);
out.set("base_half", base_pr).set("pr_five_sixths", answer);
{
  "base_half": [
    0.6,
    0.75
  ],
  "pr_five_sixths": [
    0.5,
    0.5
  ]
}

Compute [precision, recall] under rule prob > sixths / 6.0 so precision divides tp by tp + fp alone.

Read the result carefully

Reporting "100% precision" in isolation sounds unimpeachable, yet any classifier whose top row is truly positive can achieve 1.00 precision by raising its cutoff high enough to flag almost nothing. Pairing precision with recall exposes the cost immediately: reaching 1.00 precision at 5 / 6 left two of four positive cases (0.75 and 0.40) unflagged.

Push the cutoff above the top score 0.95 and nothing is flagged at all: precision becomes zero divided by zero, which is undefined rather than perfect or zero. A report must say so instead of printing a number.

Recap

  • At sixths = 5 (5 / 6), precision = 2 / 2 = 1.00 and recall = 2 / 4 = 0.50.
  • Precision rises even as TP drops (3 -> 2) because TP + FP contracts faster (5 -> 2).
  • High precision without recall can hide severe under-flagging: 5 / 6 misses half of all actual positives.