Speed

Threshold Three Quarters

Raise the cutoff from 0.50 to 0.75 on the same six rows and pinpoint the exact score band where predictions flip.

The problem

Suppose false alarms are expensive enough that 0.60 is too weak to trigger action, so we tighten the operating rule from Threshold One Half (prob > 0.50) to three quarters (prob > 0.75). Which rows change their predicted class when the score column itself has not moved?

Using the identical six rows [0.90, 1], [0.80, 1], [0.65, 1], [0.60, 0], [0.40, 1], and [0.20, 0], we compute the [6, 2] matrix answer pairing each row's new decision pred_t (prob > threshold) with a flipped indicator (1 when pred_t differs from the 0.50 decision, 0 otherwise).

Work through the numbers

Compare prob > 0.75 against the prob > 0.50 baseline [1, 1, 1, 1, 0, 0]:

  • Row 0 (0.90, y = 1): 0.90 > 0.75 stays 1, so [pred_t, flipped] = [1, 0].
  • Row 1 (0.80, y = 1): 0.80 > 0.75 stays 1, so [1, 0].
  • Row 2 (0.65, y = 1): 0.65 <= 0.75 drops from 1 to 0, so [0, 1] (flipped).
  • Row 3 (0.60, y = 0): 0.60 <= 0.75 drops from 1 to 0, so [0, 1] (flipped).
  • Row 4 (0.40, y = 1): 0.40 <= 0.75 stays 0, so [0, 0].
  • Row 5 (0.20, y = 0): 0.20 <= 0.75 stays 0, so [0, 0].

Predicted positives fall from four ([1, 1, 1, 1, 0, 0]) to two ([1, 1, 0, 0, 0, 0]). Geometrically, moving the cutoff from 0.50 to 0.75 sweeps the half-open interval (0.50, 0.75]: only scores inside that swept band (0.65 and 0.60) flip. Lowering threshold to 0.25 instead sweeps (0.25, 0.50], flipping row 4 (0.40) alone from 0 to 1.

The live model

The shaded band marks the score interval between 0.50 and threshold, while bars whose decisions changed from 0.50 highlight in orange (FLIP). Drag threshold between 0.125 and 0.875: every orange bar tip sits inside the band or on its upper edge, confirming that rows outside the swept interval never change class.

At cutoff 0.75, rows 2 (0.65) and 3 (0.60) inside the shaded band (0.50, 0.75] flip to pred 0 in orange while rows 0..1 stay pred 1.
let threshold = scene.parameter("threshold", 0.75, 0.125, 0.875, 0.125);
let prob = input.slice(1, 0, 1);
let label = input.select(1, 1);
let pred_half = prob.gt(0.5).to(DType.F64);
let pred_t = prob.gt(threshold).to(DType.F64);
let diff = pred_t - pred_half;
let flipped = diff * diff;
let cols = torch.list().add(pred_t).add(flipped);
let answer = torch.cat(cols, 1);
out.set("decisions_and_flips", answer);
{
  "decisions_and_flips": [
    [
      1,
      0
    ],
    [
      1,
      0
    ],
    [
      0,
      1
    ],
    [
      0,
      1
    ],
    [
      0,
      0
    ],
    [
      0,
      0
    ]
  ]
}
Watch the parameter change

Your turn

Build the [N, 2] matrix answer with column 0 equal to pred_t (prob > threshold) and column 1 equal to 1.0 wherever pred_t differs from pred_half (prob > 0.5), both for threshold > 0.5 and threshold < 0.5. The starter uses pred_half - pred_t, which turns negative (-1) whenever threshold < 0.5 lifts a row from 0 to 1. Check tests cutoffs on both sides of 0.50.

Starter model computes signed difference pred_t - pred_half, producing -1 instead of +1 on flipped rows.
let threshold = scene.parameter("threshold", 0.75, 0.125, 0.875, 0.125);
let prob = input.slice(1, 0, 1);
let label = input.select(1, 1);
let pred_half = prob.gt(0.5).to(DType.F64);
let pred_t = prob.gt(threshold).to(DType.F64);
# Make flipped equal 1.0 whenever pred_t != pred_half on either side of 0.5.
let flipped = pred_t - pred_half;
let cols = torch.list().add(pred_t).add(flipped);
let answer = torch.cat(cols, 1);
out.set("decisions_and_flips", answer);
{
  "decisions_and_flips": [
    [
      1,
      0
    ],
    [
      1,
      0
    ],
    [
      0,
      -1
    ],
    [
      0,
      -1
    ],
    [
      0,
      0
    ],
    [
      0,
      0
    ]
  ]
}

Compute the [N, 2] matrix answer with column 0 as pred_t (prob > threshold) and column 1 as 1.0 whenever pred_t differs from pred_half (prob > 0.5).

Read the result carefully

Tightening the cutoff from 0.50 to 0.75 achieved our goal on row 3 (0.60, y = 0), turning a false alarm into a true negative, yet it unavoidably dragged row 2 (0.65, y = 1) down with it because 0.65 also sits below 0.75. Whenever a positive row and a negative row share the swept band (0.50, 0.75], moving a single scalar cutoff flips both together.

Recap

  • Raising the cutoff to 0.75 changes decisions from [1, 1, 1, 1, 0, 0] to [1, 1, 0, 0, 0, 0].
  • Exactly the rows inside the swept interval (0.50, 0.75]—row 2 (0.65) and row 3 (0.60)—flip class (flipped = 1).
  • Because (pred_t - pred_half) is -1 when threshold < 0.50 and +1 when threshold > 0.50, squaring (diff * diff) marks flips symmetrically in {0, 1}.