Speed

Threshold Five Sixths Counts

Raise the cutoff to 5/6 on the nine scored rows and tally [TP, FP, FN, TN] = [2, 0, 2, 5] as both false alarms clear.

The problem

At Threshold One Half Counts (sixths = 3), two negative rows—0.70 and 0.60—slipped into the flagged pool, giving [TP, FP, FN, TN] = [3, 2, 1, 3]. To eliminate both false alarms, we raise the cutoff above 0.70 to five sixths (sixths = 5, so cutoff = 5 / 6 ≈ 0.8333).

On the identical 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 [tp, fp, miss_pos, tn] at sixths = 5.

Work through the numbers

Trace which rows remain above 5 / 6 ≈ 0.8333 and which fall below:

  • Rows 0, 1 (0.95, 0.90) exceed 0.8333 and carry y = 1, giving TP = 2 and FP = 0 (pred_pos = 2).
  • Three rows sit inside the swept interval (0.50, 0.8333]: row 2 (0.75, y = 1) moves from TP into FN, while rows 3, 4 (0.70, 0.60, both y = 0) move from FP into TN.
  • Combining row 2 (0.75) with row 5 (0.40) gives FN = 2; combining rows 3, 4 with rows 6, 7, 8 (0.30, 0.15, 0.10) gives TN = 5.

The confusion vector shifts from [3, 2, 1, 3] at 3 / 6 to [2, 0, 2, 5] at 5 / 6 (2 + 0 + 2 + 5 = 9). Notice the pool conservation: actual positives remain TP + FN = 2 + 2 = 4, actual negatives remain FP + TN = 0 + 5 = 5, and flagged alerts shrink from 5 down to 2 pure true positives.

The live model

Four cell cards show [TP, FP, FN, TN] above two pool bars comparing flagged = TP + FP against actual_pos = TP + FN. Step sixths from 3 ([3, 2, 1, 3]) to 4 ([3, 1, 1, 4]) and 5 ([2, 0, 2, 5]): at 5 / 6, the amber FP card hits 0 so the flagged pool (2) becomes a strict subset of the 4 actual positives.

At cutoff 5/6, confusion cards show TP 2, FP 0, FN 2, TN 5 with flagged pool 2 and actual pos pool 4.
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 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 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("counts_five_sixths", answer);
{
  "counts_five_sixths": [
    2,
    0,
    2,
    5
  ]
}
Watch the parameter change

Your turn

Complete [tp, fp, miss_pos, tn] under prob > sixths / 6.0 so miss_pos counts actual positives left at or below cutoff. The starter sets miss_pos to neg_pred.sum(), counting all 7 unflagged rows—including 5 true negatives—as missed positives. Check tests unseen tables and sixths cutoffs.

Starter model counts all 7 unflagged rows as FN instead of masking by positive true labels.
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 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.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("counts_five_sixths", answer);
{
  "counts_five_sixths": [
    2,
    0,
    7,
    5
  ]
}

Compute [tp, fp, miss_pos, tn] under rule prob > sixths / 6.0 so miss_pos counts only unflagged positive rows.

Read the result carefully

Eliminating the two false positives at 0.70 and 0.60 cost us row 2 (0.75, y = 1) only because we jumped in sixths from 4 / 6 ≈ 0.6667 to 5 / 6 ≈ 0.8333, sweeping across 0.70 and 0.75 in one step. At sixths = 5, zero false positives (FP = 0) means the flagged pool (2) contains no noise at all, while FN = 2 means half of the 4 positives sit unflagged.

Recap

  • Raising the cutoff to 5 / 6 (sixths = 5) turns [3, 2, 1, 3] into [TP, FP, FN, TN] = [2, 0, 2, 5].
  • Rows 3, 4 (0.70, 0.60) move from FP to TN, and row 2 (0.75) moves from TP to FN.
  • With FP = 0, all 2 flagged rows are true positives, while 2 of the 4 actual positives remain missed.