Scale One Row
Transform a single observation into [0, 1] feature coordinates by subtracting pinned column minimums and dividing by column spans.
The problem
Once column minimums and maximums are pinned on a training table, how does min-max scaling convert one raw observation into unitless coordinates? Consider the four-row training table [[10, 100], [20, 250], [30, 350], [50, 600]] and pick row_index , whose raw values are [20, 250].
Dividing [20, 250] directly by the column maximums [50, 600] gives [0.4, 0.4167], which fails to map the minimum row [10, 100] to zero. Exact min-max scaling measures how far a value sits above its column minimum as a fraction of the column's span: .
Work through the numbers
First read the pinned column bounds from [[10, 100], [20, 250], [30, 350], [50, 600]]. Column has , , and span . Column has , , and span .
Now transform row_index ([20, 250]) coordinate by coordinate. In column , compute . In column , compute . Row maps to [0.25, 0.3].
Check the remaining rows with the same formula. Row ([10, 100]) sits at both minimums and maps to [0, 0]. Row ([30, 350]) sits halfway across both spans ( and ) and maps to [0.5, 0.5]. Row ([50, 600]) sits at both maximums and maps to [1, 1].
The live model
The bars display the selected row's scaled coordinates in alongside reference ticks at , , and . At default row_index , the bars stand at [0.25, 0.3]. Dragging row_index to drops both coordinates to [0, 0]; dragging to centers both at [0.5, 0.5]; dragging to fills both unit bars to [1, 1].
![Unit-interval gauges for row_index 1 ([20, 250]) showing scaled feature proportions 0.25 and 0.3.](../assets/ml/scale-one-row--demo.png)
let row_index = scene.parameter("row_index", 1.0, 0.0, 3.0, 1.0);
let lo = input.amin(0);
let hi = input.amax(0);
let row = input.select(0, int(row_index));
let answer = (row - lo).div(hi - lo);
out.set("scaled_row", answer);
{
"scaled_row": [
0.25,
0.3
]
}Watch the parameter change
Your turn
The starter program returns [0.4, 0.4167] on row instead of [0.25, 0.3] and never maps the minimum row to [0, 0]. Set answer to the min-max scaled coordinate vector for row row_index using input's per-column minimums and maximums; Check tests different selected row indices and unseen multi-column tables.
![Starter gauges dividing row 1 by max only ([0.4, 0.42]) instead of min-max proportions [0.25, 0.3].](../assets/ml/scale-one-row--exercise.png)
let row_index = scene.parameter("row_index", 1.0, 0.0, 3.0, 1.0);
let hi = input.amax(0);
let row = input.select(0, int(row_index));
let answer = row.div(hi);
out.set("scaled_row", answer);
{
"scaled_row": [
0.4,
0.4166666666666667
]
}Select row int(row_index) from input and return its min-max scaled coordinate vector using input's column minimums and maximums.
Read the result carefully
Notice the geometric meaning of [0.25, 0.3]: row sits 25 percent of the way from minimum to maximum in feature , and 30 percent of the way from minimum to maximum in feature . Both numbers are now pure proportions with no physical units attached; multiplying column by rescales , , and together, canceling out completely in .
Notice also why shifting the numerator without shifting the denominator is still wrong: would map even the maximum row short of whenever .
Recap
- Min-max scaling maps one row via , using per-column minimums and maximums .
- Every coordinate becomes a unitless fraction of its column's observed training span, placing the minimum at and the maximum at .
- Rescaling a column by any positive unit factor leaves its min-max coordinates unchanged because numerator and denominator scale together.