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 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, and are pinned once on the training prefix and stored as a parameter matrix [pinned_min, pinned_max].
Work through the numbers
Take the training prefix of length train_rows : [[10, 200], [20, 500], [30, 300], [40, 600]]. Scan column across those four rows: values [10, 20, 30, 40] have and .
Scan column across the same four training rows: values [200, 500, 300, 600] have and . Stacking the minimum row above the maximum row produces the pinned boundary table [[10, 200], [40, 600]].
Contrast that against a leaky full-table reduction over all six rows. Row ([5, 900]) would drag column 's minimum down to and push column 's maximum up to , while row ([80, 100]) would push column 's maximum to and drag column 's minimum down to , producing [[5, 100], [80, 900]].
The live model
The diagram plots each column's pinned interval alongside all six raw observations, coloring training rows blue and held-out rows amber. At default train_rows , the pinned bounds are [[10, 200], [40, 600]] and both held-out rows sit outside the training intervals. At train_rows , bounds narrow to [[10, 200], [20, 500]]; at train_rows , row enters training and widens bounds to [[5, 200], [40, 900]]; at train_rows , 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.](../assets/ml/min-and-max-are-pinned--demo.png)
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.](../assets/ml/min-and-max-are-pinned--exercise.png)
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 , , , and are allowed to sit below or above . Later pages show how those out-of-range values map cleanly to numbers below or above without refitting the ruler.
Recap
- Min-max scaling stores two -element vectors learned strictly from the training split: column minimums and column maximums .
- 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.