← All Posts
Deep Learning · Data Preparation and Preprocessing · Part 6

Feature Scaling

Scaling defines the units in which a model reads numerical inputs. Changing those units can change distances, the effect of a coefficient penalty, or the speed of optimization. Scaling is useful when that change serves the model and task; it does not automatically make predictions better.

This chapter is the map for the feature-scaling series. Start with the effect you want, follow one concrete fit-and-reuse example, then choose a method chapter. The detailed derivations and implementations live in those chapters so you do not need to read the same calculation repeatedly.

Why changing the units can change the result

Suppose a nearest-neighbor model compares people using age and activity duration. A duration difference of 60 minutes contributes 60² to raw squared Euclidean distance. Express the same duration in hours and it contributes 1². The age coordinate did not change, so the model now weighs the two differences differently.

A large numerical range can dominate a distance, but that does not prove the corresponding feature is unimportant or that unit variance is the correct weighting. Scaling chooses a metric. The worked nearest-neighbor example changes units and tracks the neighbor without assuming which answer is right.

Other models react for different reasons. Rescaling a feature changes the coefficient needed to express the same prediction, which changes a penalty on coefficient size. It can also make gradient-descent steps easier to tune across parameters. These are separate effects, developed in When Scaling Matters.

Choose what the transformation should accomplish

Most feature scalers work down each training column: learn one center or divisor per feature, then reuse it. Row normalization works across each example: calculate a divisor from that row’s own coordinates. Decide which axis you mean before choosing an API.

MethodReference it usesWhat to remember
StandardizationTraining column’s mean and standard deviationNonconstant training columns get mean 0 and variance 1. The distribution’s shape remains.
Min-maxTraining column’s minimum and maximumMaps training extrema to chosen endpoints. Future values can lie outside them.
Robust scalingTraining median and interquartile rangeUses the middle of the distribution to set the scale. Outliers remain in the data.
Max-absTraining column’s largest absolute valueZero stays zero. A single extreme reference value can set a large divisor.
Unit-norm rowsEach row’s own length under the chosen normNonzero rows get unit length. Their original magnitudes are discarded.

The method chapters handle constant columns, missing inputs, and optional clipping explicitly. “Normalization” alone does not specify one of these operations; use the terminology comparison when a paper or API is ambiguous.

Follow one scaler from fitting to prediction

Use one feature with training values 10, 20, 30, and 40. Their mean is 25. Their population standard deviation is the square root of the average squared distance from 25, approximately 11.1803. A standardizer saves these two numbers.

A future value of 50 then becomes (50 − 25) / 11.1803, approximately 2.2361. It does not change the saved mean or divisor. That is the distinction between fit and transform:

Training rows → saved scaler → future inputs
01 · REFERENCESelect training rows10, 20, 30, 40The future value 50 is outside this fitting pool.
02 · FITLearn a center and scaleMean 25 · SD 11.1803Save the fitted statistics with the model.
03 · TRANSFORMReuse the saved numbersFuture 50 → 2.2361Subtract 25, then divide by 11.1803. No refitting.
04 · EVALUATEJudge the whole modelScaler + estimatorUse held-out outcomes to assess the preprocessing choice.
Step 1: the scaler learns from training rows only. Validation and future rows reuse the result.
One feature keeps the example readable. A multi-feature standardizer repeats the fit separately for each selected column. In cross-validation, each training fold gets its own fitted scaler.

Fit the estimator on transformed training rows, and predict from validation or future rows transformed by that same scaler. A pipeline fitted within each cross-validation fold keeps this boundary intact. Fitting a scaler once on the whole dataset before cross-validation allows held-out rows to influence the representation.

Future data need not have mean 0, variance 1, or values within the training min-max interval. Recomputing statistics merely to force those properties changes the transform that the estimator receives. The standardization code separates learning the statistics from reusing them.

Check what the model actually depends on

MechanismWhat scaling can change
Euclidean distanceRelative contributions of feature differences, affecting neighbors or clusters.
Cosine similarityColumn scaling can change direction. Multiplying a whole nonzero row by one positive number preserves direction.
Coefficient penaltiesThe cost of expressing an effect with a coefficient; tune the penalty with the chosen preprocessing.
Numerical optimizationStep sizes and conditioning. This can change convergence even when the available prediction functions are the same.
Covariance-based PCAWhich directions account for the most variance. Scaling changes the variance objective.

Ordinary numerical threshold trees usually do not need feature scaling. Positive affine changes preserve the candidate training partitions in exact arithmetic. That does not mean every monotonic transform yields identical predictions on unseen values: threshold placement between observations can differ. The tree counterexample explains the distinction.

Sparse storage is another constraint. Subtracting a nonzero mean can fill formerly implicit zeros. See Scaling Sparse Data before applying default centering to a large sparse matrix.

Choose a reading route

If you are onboarding, read the first two chapters below, then branch according to the representation you need. Each method chapter includes a small calculation, a figure, implementation details, and primary references.

The next data-preparation topic is encoding categorical features. Encoding decides what the coordinates represent; scaling decides how those coordinates are measured.

References and further reading