What Precision and Recall Do and Do Not Say
Test true-negative invariance of precision and recall and see what negative clearance and ranking trade-offs they omit.
The problem
Look back at both formulas from Precision and Recall at One Half and Precision and Recall at Five Sixths: precision = TP / (TP + FP) and recall = TP / (TP + FN). One cell of the 2x2 confusion grid never appears in either fraction: true negatives (TN).
Starting from our cutoff-1/2 confusion vector [TP, FP, FN, TN] = [3, 2, 1, 3], we add tn_extra extra unflagged negative rows (tn_adj = TN + tn_extra) and compute [precision, recall, specificity], where specificity = tn_adj / (tn_adj + FP).
Work through the numbers
Evaluate all three rates as tn_extra grows from 0 to 45:
- At
tn_extra = 0([3, 2, 1, 3],9rows):precision = 3 / 5 = 0.60,recall = 3 / 4 = 0.75, andspecificity = 3 / (3 + 2) = 3 / 5 = 0.60. - At
tn_extra = 15([3, 2, 1, 18],24rows):specificityjumps to18 / (18 + 2) = 18 / 20 = 0.90, whileprecisionstays3 / 5 = 0.60andrecallstays3 / 4 = 0.75. - At
tn_extra = 45([3, 2, 1, 48],54rows):specificityreaches48 / 50 = 0.96(and accuracy reaches51 / 54 ≈ 0.94), yetprecisionis still0.60andrecallis still0.75.
Padding an evaluation benchmark with obvious negative cases inflates accuracy and specificity toward 1.00, while precision and recall ignore TN completely.
The live model
Three horizontal gauges plot precision, recall, and specificity on [0, 1] above a live count of tn_adj. Slide tn_extra from 0 through 45: the blue specificity bar expands from 0.60 to 0.96, whereas the amber precision (0.60) and green recall (0.75) bars stay frozen to the pixel.
![At tn_extra 0 on [3, 2, 1, 3], precision is 0.6, recall is 0.75, and specificity is 0.6.](../assets/ml/what-precision-and-recall-do-and-do-not-say--demo.png)
let tn_extra = scene.parameter("tn_extra", 0.0, 0.0, 45.0, 15.0);
let tp = input.slice(0, 0, 1);
let fp = input.slice(0, 1, 2);
let miss_pos = input.slice(0, 2, 3);
let tn = input.slice(0, 3, 4);
let tn_adj = tn + tn_extra;
let precision = tp.div(tp + fp);
let recall = tp.div(tp + miss_pos);
let specificity = tn_adj.div(tn_adj + fp);
let parts = torch.list().add(precision).add(recall).add(specificity);
let answer = torch.cat(parts, 0);
out.set("tn_adj", tn_adj).set("rates", answer);
{
"tn_adj": [
3
],
"rates": [
0.6,
0.75,
0.6
]
}Watch the parameter change
Your turn
Compute [precision, recall, specificity] from [tp, fp, miss_pos, tn] and tn_extra. The starter omits tn_extra from specificity, divides by tn + tp instead of tn_adj + fp, and leaks tn_extra into precision's denominator. Check tests unseen confusion vectors and tn_extra values.

let tn_extra = scene.parameter("tn_extra", 0.0, 0.0, 45.0, 15.0);
let tp = input.slice(0, 0, 1);
let fp = input.slice(0, 1, 2);
let miss_pos = input.slice(0, 2, 3);
let tn = input.slice(0, 3, 4);
let tn_adj = tn + tn_extra;
let precision = tp.div(tp + fp + tn_extra);
let recall = tp.div(tp + miss_pos);
let specificity = tn.div(tn + tp);
let parts = torch.list().add(precision).add(recall).add(specificity);
let answer = torch.cat(parts, 0);
out.set("tn_adj", tn_adj).set("rates", answer);
{
"tn_adj": [
3
],
"rates": [
0.6,
0.75,
0.5
]
}Compute [precision, recall, specificity] from [tp, fp, miss_pos, tn] and tn_extra on the scored table; the three formulas are worked out in the numbers section of the page.
Read the result carefully
True-negative invariance explains both the strength and the blind spot of (precision, recall). In rare-event search, ignoring TN prevents millions of quiet background records from washing out positive-class evaluation. Conversely, (P, R) does not tell you the alert rate per thousand records ((TP + FP) / N drops from 5 / 9 to 5 / 54), does not measure negative clearance (specificity), and does not rank [0.60, 0.75] against [1.00, 0.50] without an explicit summary rule—the job of F1 score.
Recap
- Neither
TP / (TP + FP)norTP / (TP + FN)depends onTN, keeping[0.60, 0.75]invariant asTNgrows from3to48. - Negative clearance
specificity = TN / (TN + FP)rises from0.60to0.96across the sametn_extrasweep. - Precision and recall omit overall alert volume
(TP + FP) / Nand need a combination rule when one rises as the other falls.