Speed

Min and Max Are Pinned

Pin column minimums and maximums strictly on the training split so future or held-out rows cannot shift the coordinate ruler.

The problem

Once you decide to rescale each column by its minimum and maximum, a subtle pipeline question decides whether evaluation is honest: which rows get to vote on those bounds? Suppose a six-row table has columns [tenure_months, monthly_spend]: [[10, 200], [20, 500], [30, 300], [40, 600], [5, 900], [80, 100]], where the first train_rows =4= 4 rows form the training split and the last two rows ([5, 900] and [80, 100]) arrive later at evaluation time.

Computing minimums and maximums over the entire six-row matrix before splitting leaks future extremes into the preprocessor. Instead, lo\mathrm{lo} and hi\mathrm{hi} are pinned once on the training prefix and stored as a 2×D2 \times D parameter matrix [pinned_min, pinned_max].

Work through the numbers

Take the training prefix of length train_rows =4= 4: [[10, 200], [20, 500], [30, 300], [40, 600]]. Scan column 00 across those four rows: values [10, 20, 30, 40] have lo0=10\mathrm{lo}_0 = 10 and hi0=40\mathrm{hi}_0 = 40.

Scan column 11 across the same four training rows: values [200, 500, 300, 600] have lo1=200\mathrm{lo}_1 = 200 and hi1=600\mathrm{hi}_1 = 600. Stacking the minimum row above the maximum row produces the pinned 2×22 \times 2 boundary table [[10, 200], [40, 600]].

Contrast that against a leaky full-table reduction over all six rows. Row 44 ([5, 900]) would drag column 00's minimum down to 55 and push column 11's maximum up to 900900, while row 55 ([80, 100]) would push column 00's maximum to 8080 and drag column 11's minimum down to 100100, producing [[5, 100], [80, 900]].

The live model

The diagram plots each column's pinned [lo,hi][\mathrm{lo}, \mathrm{hi}] interval alongside all six raw observations, coloring training rows blue and held-out rows amber. At default train_rows =4= 4, the pinned bounds are [[10, 200], [40, 600]] and both held-out rows sit outside the training intervals. At train_rows =2= 2, bounds narrow to [[10, 200], [20, 500]]; at train_rows =5= 5, row 44 enters training and widens bounds to [[5, 200], [40, 900]]; at train_rows =6= 6, bounds become [[5, 100], [80, 900]].

Two-column interval plot showing pinned bounds [[10, 200], [40, 600]] from 4 training rows while held-out rows sit outside.
let train_rows = scene.parameter("train_rows", 4.0, 2.0, 6.0, 1.0);
let tr = input.slice(0, 0, int(train_rows));
let lo = tr.amin(0).unsqueeze(0);
let hi = tr.amax(0).unsqueeze(0);
let answer = torch.cat(torch.list().add(lo).add(hi), 0);
out.set("pinned_bounds", answer);
{
  "pinned_bounds": [
    [
      10,
      200
    ],
    [
      40,
      600
    ]
  ]
}
Watch the parameter change

Your turn

The starter program leaks held-out rows into the boundary table, returning [[5, 100], [80, 900]] instead of [[10, 200], [40, 600]] at train_rows = 4. Set answer to the two-row matrix [column_mins, column_maxes] pinned strictly on the first train_rows rows of input; Check varies both the feature table and the split point train_rows.

Starter plot leaking all 6 rows into bounds [[5, 100], [80, 900]] instead of pinning on 4 training rows.
let train_rows = scene.parameter("train_rows", 4.0, 2.0, 6.0, 1.0);
let lo = input.amin(0).unsqueeze(0);
let hi = input.amax(0).unsqueeze(0);
let answer = torch.cat(torch.list().add(lo).add(hi), 0);
out.set("pinned_bounds", answer);
{
  "pinned_bounds": [
    [
      5,
      100
    ],
    [
      80,
      900
    ]
  ]
}

Return the 2-row matrix [column_mins, column_maxes] pinned strictly on the first train_rows rows of input.

Read the result carefully

Think of pinned_min and pinned_max as learned parameters of the feature pipeline, no different from regression weights. At deployment time your model scores one incoming request at a time; future rows do not exist yet when training finishes, so any notebook that scales the whole CSV before splitting cannot be reproduced honestly in production.

Pinning bounds on training rows also means held-out values like 55, 8080, 100100, and 900900 are allowed to sit below lo\mathrm{lo} or above hi\mathrm{hi}. Later pages show how those out-of-range values map cleanly to numbers below 00 or above 11 without refitting the ruler.

Recap

  • Min-max scaling stores two DD-element vectors learned strictly from the training split: column minimums lo\mathrm{lo} and column maximums hi\mathrm{hi}.
  • Computing bounds before train/test splitting leaks future extremes (turning [[10, 200], [40, 600]] into [[5, 100], [80, 900]]) and invalidates evaluation.
  • Once pinned on training rows, the boundary matrix stays frozen for validation, testing, and live inference.