Speed

Confusion at Three Quarters

Tally [TP, FP, FN, TN] = [2, 0, 2, 2] at cutoff 0.75 and see how false alarms vanish at the cost of one lost true positive.

The problem

In Threshold Three Quarters, raising the cutoff from 0.50 to 0.75 flipped two rows inside (0.50, 0.75]: row 2 (0.65, y = 1) and row 3 (0.60, y = 0). How do those two individual flips reshape the 2x2 confusion grid?

On the fixed six-row table [0.90, 1], [0.80, 1], [0.65, 1], [0.60, 0], [0.40, 1], and [0.20, 0], we compute [TP, FP, FN, TN] at threshold = 0.75 and compare every cell against its 0.50 baseline [3, 1, 1, 1].

Work through the numbers

Group the threshold = 0.75 decisions [1, 1, 0, 0, 0, 0] by true label y = [1, 1, 1, 0, 1, 0]:

  • Rows 0, 1 (0.90, 0.80) have pred = 1 and y = 1, giving TP = 2 (down 1 from 3 because row 2 dropped below 0.75).
  • Zero rows have pred = 1 and y = 0, giving FP = 0 (down 1 from 1 because row 3 dropped below 0.75).
  • Rows 2, 4 (0.65, 0.40) have pred = 0 and y = 1, giving FN = 2 (up 1 from 1).
  • Rows 3, 5 (0.60, 0.20) have pred = 0 and y = 0, giving TN = 2 (up 1 from 1).

The cell vector moves from [3, 1, 1, 1] to [2, 0, 2, 2], a signed change of [-1, -1, +1, +1]. Check accuracy at both cutoffs: (3 + 1) / 6 = 4 / 6 at 0.50 and (2 + 2) / 6 = 4 / 6 at 0.75. Accuracy stayed flat at two thirds while errors rotated from one false alarm plus one miss to zero false alarms plus two misses. Meanwhile, an intermediate cutoff of 0.625 yields [3, 0, 1, 2] (5 / 6 accuracy).

The live model

Four cards show [TP, FP, FN, TN] at the active threshold alongside each cell's signed shift delta relative to the 0.50 grid [3, 1, 1, 1]. Move threshold from 0.50 to 0.625 (delta = [0, -1, 0, +1]) and then to 0.75 (delta = [-1, -1, +1, +1]): every loss in TP appears one-for-one in FN, and every drop in FP appears one-for-one in TN.

At cutoff 0.75, cells [TP, FP, FN, TN] equal [2, 0, 2, 2] with deltas [-1, -1, 1, 1] vs 0.50 and 4 of 6 correct.
let threshold = scene.parameter("threshold", 0.75, 0.125, 0.875, 0.125);
let prob = input.select(1, 0);
let label = input.select(1, 1);
let neg_label = label.rsub(1.0);
let p0 = prob.gt(0.5).to(DType.F64);
let n0 = p0.rsub(1.0);
let b1 = torch.list().add((p0 * label).sum().reshape(1));
let b2 = b1.add((p0 * neg_label).sum().reshape(1));
let b3 = b2.add((n0 * label).sum().reshape(1));
let base_counts = torch.cat(b3.add((n0 * neg_label).sum().reshape(1)), 0);
let pred = prob.gt(threshold).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 tn = (neg_pred * neg_label).sum();
let top = torch.list().add(tp.reshape(1)).add(fp.reshape(1));
let answer = torch.cat(top.add(miss_pos.reshape(1)).add(tn.reshape(1)), 0);
out.set("baseline_half", base_counts).set("confusion_three_quarters", answer);
{
  "baseline_half": [
    3,
    1,
    1,
    1
  ],
  "confusion_three_quarters": [
    2,
    0,
    2,
    2
  ]
}
Watch the parameter change

Your turn

Complete [tp, fp, miss_pos, tn] so tn counts only unflagged negative rows (pred = 0 and y = 0). The starter subtracts tp + fp from total without subtracting miss_pos, inflating tn by every missed positive (4 instead of 2 at 0.75). The check reruns the fix on a five-row table at 0.75 and a six-row table at 0.625, where tn must exclude every missed positive.

Starter model leaves missed positives inside TN, reporting TN 4 instead of 2 at cutoff 0.75.
let threshold = scene.parameter("threshold", 0.75, 0.125, 0.875, 0.125);
let prob = input.select(1, 0);
let label = input.select(1, 1);
let total = float(prob.numel());
let neg_label = label.rsub(1.0);
let p0 = prob.gt(0.5).to(DType.F64);
let n0 = p0.rsub(1.0);
let b1 = torch.list().add((p0 * label).sum().reshape(1));
let b2 = b1.add((p0 * neg_label).sum().reshape(1));
let b3 = b2.add((n0 * label).sum().reshape(1));
let base_counts = torch.cat(b3.add((n0 * neg_label).sum().reshape(1)), 0);
let pred = prob.gt(threshold).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 tn = (tp + fp).rsub(total);
let top = torch.list().add(tp.reshape(1)).add(fp.reshape(1));
let answer = torch.cat(top.add(miss_pos.reshape(1)).add(tn.reshape(1)), 0);
out.set("baseline_half", base_counts).set("confusion_three_quarters", answer);
{
  "baseline_half": [
    3,
    1,
    1,
    1
  ],
  "confusion_three_quarters": [
    2,
    0,
    2,
    4
  ]
}

Compute [tp, fp, miss_pos, tn] under rule prob > threshold so tn counts only unflagged negative rows.

Read the result carefully

Comparing [3, 1, 1, 1] at 0.50 with [2, 0, 2, 2] at 0.75 proves why single-number accuracy cannot guide threshold selection: both grids score 4 / 6, yet [2, 0, 2, 2] eliminates false positives completely by accepting an extra missed positive. Every upward step of threshold can only decrease or preserve TP and FP while increasing or preserving FN and TN.

Recap

  • At threshold = 0.75, confusion counts become [TP, FP, FN, TN] = [2, 0, 2, 2].
  • Relative to 0.50 ([3, 1, 1, 1]), cell changes [-1, -1, +1, +1] conserve both ΔTP + ΔFN = 0 and ΔFP + ΔTN = 0.
  • Accuracy ties at 4 / 6 across 0.50 and 0.75 even though FP drops to 0 and FN doubles to 2.