← Back to the chapter

Technical detail · Feature Scaling and Leakage Controls

Two examples of a contaminated scale

Take training voltages 3.4 V, 3.6 V, and 3.8 V. Min-max scaling uses x′=(x−3.4)/(3.8−3.4)x'=(x-3.4)/(3.8-3.4). The training value 3.6 V becomes 0.2/0.4=0.50.2/0.4=0.5. A later test reading of 4.0 V becomes 0.6/0.4=1.50.6/0.4=1.5, outside the training range but honest. Refitting with 4.0 V would pull that test point to 1.0 and let test information alter evaluation. The saved transformation also lets an operator trace 1.5 back to 4.0 V.

For temperature, training values range from 18 to 28 degrees C, so 23 degrees C becomes 0.5. If the test set contains a 38 degree overheating event and you fit on all data, 23 degrees C becomes 0.25 instead. Training now benefits from knowledge that the future maximum exists. Its representation no longer matches what would have happened before that event was observed.

The arithmetic exposes the boundary: validation and test values may be transformed, but they cannot help determine the transformation. Persisting the scaler preserves that boundary at inference. A model trained on z-scored inputs can misbehave when production supplies raw values or values scaled with another run’s statistics.

← Back to the chapter