Two Confusion Grids
Compare conservative Grid A [3, 1, 3, 23] and aggressive Grid B [6, 18, 0, 6] on the same 30-row benchmark.
The problem
Suppose two classifiers evaluate the exact same 30-row held-out set containing 6 genuine positives and 24 genuine negatives. Grid A ([TP, FP, FN, TN] = [3, 1, 3, 23]) flags cautiously, whereas Grid B ([6, 18, 0, 6]) flags almost everything in sight. Which model is stronger, and why will a naive average of precision and recall fail to separate them?
Before computing rates, we verify that both grids share the same ground-truth benchmark and compare [actual_pos, pred_pos, total_errors] across both rows as extra_fp_b moves Grid B rows between FP and TN so the benchmark stays 6 positives and 24 negatives.
Work through the numbers
Check the three totals [TP + FN, TP + FP, FP + FN] on each 30-row confusion vector at extra_fp_b = 0:
- Grid A (
[3, 1, 3, 23]):actual_pos = 3 + 3 = 6(24negatives1 + 23 = 24),pred_pos = 3 + 1 = 4flagged rows, andtotal_errors = 1 + 3 = 4mistakes (26 / 30correct). - Grid B (
[6, 18, 0, 6]):actual_pos = 6 + 0 = 6(24negatives18 + 6 = 24),pred_pos = 6 + 18 = 24flagged rows (80%of the dataset), andtotal_errors = 18 + 0 = 18mistakes (12 / 30correct).
Both models face the identical 6-positive, 24-negative split, yet Grid B makes 4.5 times as many errors as Grid A (18 vs 4) by crying wolf on 18 negatives to avoid missing any positive.
Varying extra_fp_b from -6 to +6 moves rows between Grid B's FP and TN (fp_adj = 18 + extra_fp_b, tn_adj = 6 - extra_fp_b, keeping fp_adj + tn_adj = 24): at -6 Grid B is [6, 12, 0, 12] (18 flagged, 12 errors) and at +6 it is [6, 24, 0, 0] (30 flagged, 24 errors), leaving the 6-and-24 benchmark unchanged.
The live model
Paired horizontal bars compare Grid A (top group) and Grid B (bottom group) on actual_pos, pred_pos, and errors out of 30 rows, above a footer verifying fp_adj + tn_adj = 24. Slide extra_fp_b from -6 to +6: both green actual_pos bars stay equal at 6 and fp_adj + tn_adj stays 24, while Grid B's amber pred_pos and red errors bars tower over Grid A's 4 and 4.

let extra_fp_b = scene.parameter("extra_fp_b", 0.0, -6.0, 6.0, 3.0);
let tp = input.slice(1, 0, 1);
let fp = input.slice(1, 1, 2);
let miss_pos = input.slice(1, 2, 3);
let tn = input.slice(1, 3, 4);
let mask_b = torch.tensor("[[0.0], [1.0]]", DType.F64);
let fp_adj = fp + mask_b * extra_fp_b;
let tn_adj = tn - mask_b * extra_fp_b;
let actual_pos = tp + miss_pos;
let pred_pos = tp + fp_adj;
let errors = fp_adj + miss_pos;
let cols = torch.list().add(actual_pos).add(pred_pos).add(errors);
let answer = torch.cat(cols, 1);
out.set("tn_adj", tn_adj).set("grid_totals", answer);
{
"tn_adj": [
[
23
],
[
6
]
],
"grid_totals": [
[
6,
4,
4
],
[
6,
24,
18
]
]
}Watch the parameter change
Your turn
Compute the [2, 3] matrix answer with columns [actual_pos, pred_pos, errors] as extra_fp_b moves row 1 negatives between fp and tn. The starter counts tp + tn_adj (correct rows) in column 2 instead of fp_adj + miss_pos (errors). Check tests unseen two-grid benchmarks and non-zero extra_fp_b shifts.

let extra_fp_b = scene.parameter("extra_fp_b", 0.0, -6.0, 6.0, 3.0);
let tp = input.slice(1, 0, 1);
let fp = input.slice(1, 1, 2);
let miss_pos = input.slice(1, 2, 3);
let tn = input.slice(1, 3, 4);
let mask_b = torch.tensor("[[0.0], [1.0]]", DType.F64);
let fp_adj = fp + mask_b * extra_fp_b;
let tn_adj = tn - mask_b * extra_fp_b;
let actual_pos = tp + miss_pos;
let pred_pos = tp + fp_adj;
let errors = tp + tn_adj;
let cols = torch.list().add(actual_pos).add(pred_pos).add(errors);
let answer = torch.cat(cols, 1);
out.set("tn_adj", tn_adj).set("grid_totals", answer);
{
"tn_adj": [
[
23
],
[
6
]
],
"grid_totals": [
[
6,
4,
26
],
[
6,
24,
12
]
]
}Compute the [2, 3] matrix answer with columns [actual_pos, pred_pos, errors] as extra_fp_b moves Grid B rows between FP and TN.
Read the result carefully
Comparing two confusion matrices is only fair when both share TP + FN (6 actual positives) and FP + TN (24 actual negatives); otherwise differences in class prevalence confound the metrics. Once that shared 6-and-24 split is verified, the contrast is stark: Grid A trades 3 missed positives for a tiny 4-row review queue, whereas Grid B floods reviewers with 24 alerts (18 false) to catch all 6 positives.
Recap
- Grid A (
[3, 1, 3, 23]) and Grid B ([6, 18, 0, 6]) share6actual positives and24actual negatives (30rows). - At
extra_fp_b = 0, Grid A has[actual_pos, pred_pos, errors] = [6, 4, 4], while Grid B has[6, 24, 18]. - Shifting
extra_fp_bmoves Grid B rows betweenFPandTN(fp_adj + tn_adj = 24), keeping the6-and-24benchmark fixed while varying Grid B's flagged rows (18to30) and errors (12to24).