Speed

Same Scored Rows

Convert six raw logits into ordered probability scores and see why threshold experiments start from one fixed score column.

The problem

Before a classifier outputs 1 or 0, its scoring stage produces one continuous number per row. When two teams report different confusion matrices from the same trained model, nothing inside the weights had to change—each team applied a different decision threshold to the same scored rows.

To isolate threshold effects cleanly across this book, we start with six evaluated rows carrying raw log-odds logit and true binary label y: [2.2, 1], [1.4, 1], [0.6, 1], [0.4, 0], [-0.4, 1], and [-1.4, 0]. Applying sigmoid(logit * scale) = 1 / (1 + exp(-logit * scale)) maps every real score onto (0, 1).

Work through the numbers

At scale = 1.0, evaluate 1 / (1 + exp(-z)) row by row from highest logit to lowest:

  • Row 0 (z = 2.2, y = 1): 1 / (1 + exp(-2.2)) ≈ 0.9002, rounding to 0.90.
  • Row 1 (z = 1.4, y = 1): 1 / (1 + exp(-1.4)) ≈ 0.8022, rounding to 0.80.
  • Row 2 (z = 0.6, y = 1): 1 / (1 + exp(-0.6)) ≈ 0.6457, rounding to 0.65.
  • Row 3 (z = 0.4, y = 0): 1 / (1 + exp(-0.4)) ≈ 0.5987, rounding to 0.60.
  • Row 4 (z = -0.4, y = 1): by symmetry 1 - 0.5987 ≈ 0.4013, rounding to 0.40.
  • Row 5 (z = -1.4, y = 0): by symmetry 1 - 0.8022 ≈ 0.1978, rounding to 0.20.

Notice two facts before any threshold enters. Four rows are truly positive (0, 1, 2, 4) and two are truly negative (3, 5), and row 3 (0.60, true 0) outranks row 4 (0.40, true 1), so no single cutoff can separate the classes with zero errors. Multiplying logits by scale = 0.5 compresses probabilities toward [0.75, 0.67, 0.57, 0.55, 0.45, 0.33] while scale = 2.0 stretches them to [0.99, 0.94, 0.77, 0.69, 0.31, 0.06], leaving the top-to-bottom row order untouched.

The live model

Each horizontal bar shows a row's probability in [0, 1], colored green when y = 1 and amber when y = 0, with a vertical reference line at 0.50 (logit = 0). Move scale from 0.5 through 2.0: every bar stretches away from 0.50 or pulls toward it, yet rows 0..3 stay above 0.50, rows 4..5 stay below 0.50, and no two rows ever swap rank.

Six ordered probability bars [0.90, 0.80, 0.65, 0.60, 0.40, 0.20] colored by true label y with a reference line at 0.50.
let scale = scene.parameter("scale", 1.0, 0.5, 2.0, 0.5);
let logit = input.slice(1, 0, 1);
let label = input.select(1, 1);
let scaled = logit * scale;
let answer = scaled.sigmoid();
out.set("labels", label).set("probabilities", answer);
{
  "labels": [
    1,
    1,
    1,
    0,
    1,
    0
  ],
  "probabilities": [
    [
      0.9002495108803148
    ],
    [
      0.8021838885585817
    ],
    [
      0.6456563062257954
    ],
    [
      0.598687660112452
    ],
    [
      0.401312339887548
    ],
    [
      0.19781611144141825
    ]
  ]
}
Watch the parameter change

Your turn

Compute the [N, 1] probability column answer by applying the logistic sigmoid to logit * scale. The starter uses a linear approximation scaled * 0.25 + 0.5, which distorts curvature and can leave (0, 1) on steeper logits. The check reruns the sigmoid at scale = 0.5 on [1.8, 0.8, 0.0, -1.2] and at scale = 1.5 on [1.5, 0.5, -0.5, -2.0, 0.2], where the linear shortcut leaves the unit interval.

Starter model maps scaled logits linearly instead of applying the logistic sigmoid.
let scale = scene.parameter("scale", 1.0, 0.5, 2.0, 0.5);
let logit = input.slice(1, 0, 1);
let label = input.select(1, 1);
let scaled = logit * scale;
let answer = scaled * 0.25 + 0.5;
out.set("labels", label).set("probabilities", answer);
{
  "labels": [
    1,
    1,
    1,
    0,
    1,
    0
  ],
  "probabilities": [
    [
      1.05
    ],
    [
      0.85
    ],
    [
      0.65
    ],
    [
      0.6
    ],
    [
      0.4
    ],
    [
      0.15000000000000002
    ]
  ]
}

Compute the [N, 1] probability column answer by applying the logistic sigmoid to logit * scale.

Read the result carefully

Separating scoring from thresholding prevents a common debugging mistake: retraining a model when only the operating cutoff was misconfigured, or tuning a cutoff when the underlying score ranking itself mixes positives and negatives. In the remaining five lessons of this book, we freeze the rounded six-row score column [0.90, 0.80, 0.65, 0.60, 0.40, 0.20] and trace what happens as the cutoff moves from 0.50 to 0.75.

Recap

  • Logistic scoring maps [2.2, 1.4, 0.6, 0.4, -0.4, -1.4] onto [0.90, 0.80, 0.65, 0.60, 0.40, 0.20].
  • Positive scaling (scale > 0) stretches or compresses probabilities around 0.50 without altering row rank.
  • Because negative row 3 (0.60) sits above positive row 4 (0.40), every threshold on these six rows trades false positives against missed positives.