Speed

Threshold One Half

Apply the strict cutoff prob > 0.50 to the six scored rows and trace which four rows receive predicted class 1.

The problem

A probability column such as [0.90, 0.80, 0.65, 0.60, 0.40, 0.20] from Same Scored Rows cannot trigger an automated action until a decision rule converts each continuous score into 1 or 0. Most libraries default to threshold = 0.50, predicting 1 whenever prob > 0.50 and 0 when prob <= 0.50.

We apply prob > threshold to the fixed six-row table [0.90, 1], [0.80, 1], [0.65, 1], [0.60, 0], [0.40, 1], and [0.20, 0], returning the [6, 1] binary decision column answer.

Work through the numbers

Compare each row's score against threshold = 0.50:

  • Row 0: 0.90 > 0.50 is true, so pred = 1 (matches y = 1).
  • Row 1: 0.80 > 0.50 is true, so pred = 1 (matches y = 1).
  • Row 2: 0.65 > 0.50 is true, so pred = 1 (matches y = 1).
  • Row 3: 0.60 > 0.50 is true, so pred = 1 (disagrees with y = 0).
  • Row 4: 0.40 > 0.50 is false, so pred = 0 (disagrees with y = 1).
  • Row 5: 0.20 > 0.50 is false, so pred = 0 (matches y = 0).

At 0.50, four rows (0, 1, 2, 3) land above the line and receive 1, while two rows (4, 5) land at or below the line and receive 0. Notice that threshold never inspects the true label y: row 3 (0.60, y = 0) gets pred = 1 because 0.60 clears 0.50, and row 4 (0.40, y = 1) gets pred = 0 because 0.40 falls short. Stepping threshold up to 0.625 drops row 3 to 0, and stepping down to 0.375 lifts row 4 to 1.

The live model

The red vertical cutoff line slices across all six score bars: bars extending past the red line turn blue (pred = 1) and bars stopping left of the line turn slate (pred = 0), while the right column prints both pred and true y. Slide threshold in 0.125 increments from 0.125 (6 ones) through 0.50 (4 ones) up to 0.875 (1 one) to watch each row flip as the red line crosses its tip.

At cutoff 0.5, rows 0..3 above the red line get pred 1 in blue while rows 4..5 below get pred 0 in slate.
let threshold = scene.parameter("threshold", 0.5, 0.125, 0.875, 0.125);
let prob = input.slice(1, 0, 1);
let label = input.select(1, 1);
let answer = prob.gt(threshold).to(DType.F64);
out.set("scores", prob).set("decisions", answer);
{
  "scores": [
    [
      0.9
    ],
    [
      0.8
    ],
    [
      0.65
    ],
    [
      0.6
    ],
    [
      0.4
    ],
    [
      0.2
    ]
  ],
  "decisions": [
    [
      1
    ],
    [
      1
    ],
    [
      1
    ],
    [
      1
    ],
    [
      0
    ],
    [
      0
    ]
  ]
}
Watch the parameter change

Your turn

Compute the [N, 1] decision column answer using the strict comparison prob > threshold. The starter compares against a fixed 0.0 instead of threshold, predicting 1 on every positive probability. The check reruns the rule at 0.50 on [0.85, 0.50, 0.35, 0.10], where the tied 0.50 row must stay 0, and at 0.625 on a five-row column.

Starter model compares probabilities against 0.0 instead of threshold, predicting 1 on all six rows.
let threshold = scene.parameter("threshold", 0.5, 0.125, 0.875, 0.125);
let prob = input.slice(1, 0, 1);
let label = input.select(1, 1);
let answer = prob.gt(0.0).to(DType.F64);
out.set("scores", prob).set("decisions", answer);
{
  "scores": [
    [
      0.9
    ],
    [
      0.8
    ],
    [
      0.65
    ],
    [
      0.6
    ],
    [
      0.4
    ],
    [
      0.2
    ]
  ],
  "decisions": [
    [
      1
    ],
    [
      1
    ],
    [
      1
    ],
    [
      1
    ],
    [
      1
    ],
    [
      1
    ]
  ]
}

Compute the [N, 1] decision column answer equal to 1.0 when prob > threshold and 0.0 otherwise.

Read the result carefully

Defaulting to 0.50 feels neutral because 0.50 sits halfway between 0 and 1, yet on a finite table it partitions rows into [0.90, 0.80, 0.65, 0.60] versus [0.40, 0.20]. Any cutoff strictly between 0.40 and 0.60—for example 0.45 or 0.55—produces the exact same [1, 1, 1, 1, 0, 0] predictions on these six rows; predictions only change when the threshold crosses an actual row score.

Recap

  • Rule prob > 0.50 maps [0.90, 0.80, 0.65, 0.60, 0.40, 0.20] to [1, 1, 1, 1, 0, 0].
  • Thresholding uses only the score column prob, never the true label y, leaving one false alarm on row 3 and one miss on row 4.
  • Moving the cutoff within (0.40, 0.60) changes zero decisions; a prediction flips only when the cutoff crosses a row's score.