Precision and Recall at One Half
Divide shared true positives TP = 3 by flagged count 5 and positive count 4 to get precision 0.60 and recall 0.75 at cutoff 1/2.
The problem
From Threshold One Half Counts, cutoff sixths = 3 (3 / 6 = 0.50) partitions our nine rows into TP = 3, FP = 2, FN = 1, and TN = 3. Two different stakeholders now ask two different accuracy-free questions: "When the model raises an alert, how often is it right?" (precision) and "Of all genuine positives, what fraction did the model catch?" (recall).
On [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 = 3 and watch how the pair moves across sixths = 1..5.
Work through the numbers
Substitute TP = 3, FP = 2, and FN = 1 at sixths = 3 (0.50):
- Precision divides caught positives by all flagged rows:
TP / (TP + FP) = 3 / (3 + 2) = 3 / 5 = 0.60. Three fifths of alerts are real; two fifths (0.70and0.60) are false alarms. - Recall divides caught positives by all actual positives:
TP / (TP + FN) = 3 / (3 + 1) = 3 / 4 = 0.75. Three quarters of genuine positives are caught; one quarter (0.40) is missed.
Notice what happens at neighboring cutoffs. Stepping up to sixths = 4 (4 / 6 ≈ 0.67) drops row 4 (0.60, y = 0), turning [3, 2, 1, 3] into [3, 1, 1, 4]: precision rises from 0.60 to 3 / 4 = 0.75 while recall stays 3 / 4 = 0.75—the two metrics cross and tie because FP == FN == 1. Stepping down to sixths = 2 (2 / 6 ≈ 0.33) lifts recall to 4 / 4 = 1.00 (4 / 6 ≈ 0.67 precision).
The live model
Two rate bars plot precision and recall on [0, 1] above fraction cards showing exact numerators and denominators (3 / 5 and 3 / 4 at 3/6). Drag sixths from 1 to 5: recall steps downward monotonically (1.00, 1.00, 0.75, 0.75, 0.50) because its denominator is fixed at 4, while precision takes the path (0.57, 0.67, 0.60, 0.75, 1.00) — climbing whenever false alarms drop out faster than true positives, and dipping from 0.67 to 0.60 at sixths = 3, where a lone true positive exits the flagged pool.

let sixths = scene.parameter("sixths", 3.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 pred = prob.gt(cutoff).to(DType.F64);
let neg_pred = pred.rsub(1.0);
let neg_label = label.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 c_list = torch.list().add(tp.reshape(1)).add(fp.reshape(1));
let counts = torch.cat(c_list.add(miss_pos.reshape(1)), 0);
let pr_list = torch.list().add(precision.reshape(1)).add(recall.reshape(1));
let answer = torch.cat(pr_list, 0);
out.set("counts", counts).set("precision_recall", answer);
{
"counts": [
3,
2,
1
],
"precision_recall": [
0.6,
0.75
]
}Watch the parameter change
Your turn
Compute [precision, recall] under prob > sixths / 6.0 with precision = tp / (tp + fp) and recall = tp / (tp + miss_pos). The starter swaps the two denominators, reporting [0.75, 0.60] instead of [0.60, 0.75]. Check evaluates unseen score tables across alternate sixths positions.

let sixths = scene.parameter("sixths", 3.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 pred = prob.gt(cutoff).to(DType.F64);
let neg_pred = pred.rsub(1.0);
let neg_label = label.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 + miss_pos);
let recall = tp.div(tp + fp);
let c_list = torch.list().add(tp.reshape(1)).add(fp.reshape(1));
let counts = torch.cat(c_list.add(miss_pos.reshape(1)), 0);
let pr_list = torch.list().add(precision.reshape(1)).add(recall.reshape(1));
let answer = torch.cat(pr_list, 0);
out.set("counts", counts).set("precision_recall", answer);
{
"counts": [
3,
2,
1
],
"precision_recall": [
0.75,
0.6
]
}Compute [precision, recall] under rule prob > sixths / 6.0 on the scored table; the two formulas are worked out in the numbers section of the page.
Read the result carefully
Look closely at the jump from sixths = 2 (4 / 6 ≈ 0.67 precision) to sixths = 3 (3 / 5 = 0.60 precision): raising the threshold actually dipped precision slightly because the single row lost between 2 / 6 and 3 / 6 was row 5 (0.40, y = 1), a true positive. Unlike recall—which is guaranteed non-increasing with cutoff—finite-sample precision wiggles down whenever a true positive exits the flagged set without any false positive leaving alongside it.
Recap
- At
sixths = 3(0.50),precision = 3 / 5 = 0.60andrecall = 3 / 4 = 0.75. - Precision and recall tie whenever
FP == FN(withTP > 0), as atsixths = 4where both equal3 / 4 = 0.75. - Recall never increases when the cutoff rises, whereas finite-sample precision dips slightly when a positive row (
0.40) leaves the flagged pool alone.