Recommended resources
The freely available resources this lesson will direct you to.
- Standardization vs Normalization Clearly Explained!www.youtube.com
- Normalization Vs. Standardization (Feature Scaling in Machine Learning)www.youtube.com
- Numerical data: Normalization | Machine Learning | Google for Developersdevelopers.google.com
- CS231n Deep Learning for Computer Visioncs231n.github.io
Welcome back. In the previous lesson, you used a gradient and a learning rate to update a model parameter. Before a model can learn effectively from numerical inputs, it often helps to put those inputs on a comparable scale.
This lesson focuses on one operation: subtract a feature vector’s mean, then divide by its standard deviation, which is calculated from its variance. You’ll work through the arithmetic by hand, then distinguish which values should be used to calculate the mean in a tabular dataset. Allow about 35 minutes.
Why change a feature’s scale?
Imagine a dataset with two input features: the number of rooms in a home and its floor area in square metres. Room counts might be single-digit numbers, while floor areas might be in the hundreds. Those numerical scales reflect different units, not necessarily different importance to the prediction.
For models trained with gradient descent, poorly matched feature scales can make optimization less straightforward. Watch the two short passages below for the basic operation and its connection to the updates you studied last time.
Standardization vs Normalization Clearly Explained!
Watch “Standardization vs Normalization Clearly Explained!” from Normalized Nerd to see what subtracting a mean and dividing by a standard deviation accomplishes, and why feature scales can affect gradient descent.
Start with standardization. Notice the distinction between changing a distribution’s mean and spread and changing its overall shape. Then watch feature scales for the example of gradient-descent updates when two inputs have very different ranges.
This operation is commonly called standardization or Z-score scaling. “Normalization” can mean several kinds of rescaling in machine learning; here, it means this particular mean-and-variance-based operation. It is useful to know the distinction because standardization does not squeeze every value into the interval from 0 to 1.

Mean, variance, and the Z-score
Read Google’s Numerical data: Normalization for the interpretation of a Z-score as a distance from the mean measured in standard deviations. The figures help connect the arithmetic to what happens to an entire feature’s values.
Numerical data: Normalization | Machine Learning | Google for Developers
Read the “Z-score scaling” section of Google’s Machine Learning Crash Course. Focus on what a positive or negative Z-score says about a value relative to the mean.
In “Z-score scaling,” begin with the definition and examples. Continue through the two histogram figures and the expandable “Click the icon to see the math” explanation. Stop after the guidance below the figures, before the paragraph beginning “Note that some distributions might be normal.” Compare each original histogram with its scaled version: look for a changed centre and numerical scale, not a newly invented shape.
Suppose our feature vector contains values, . First find its mean, the average value:
Then find its variance, the average squared distance from that mean:
The standard deviation is . It brings the measure of spread back into the same units as the original values. When , standardize each entry with
Subtracting centres the values at zero. Dividing by expresses each centred value in units of standard deviation. Notice that we divide by the square root of variance, not by variance itself.
For this complete vector, we use in the variance calculation. You may encounter a formula that divides by when estimating variance from a sample; that is a different statistical purpose. Use the convention specified for the normalization you are performing.
Normalize a vector by hand
Take the vector
Its mean is
Subtract 5 from every entry to obtain the centred vector . Square those deviations and average them:
The standard deviation is therefore , giving the normalized vector
The first entry is about 1.342 standard deviations below the original mean; the last is about 1.342 standard deviations above it. The vector still has four entries. We have changed their values, not the vector’s shape.
There is a useful way to check the result. The entries sum to zero, so their mean is zero. Their squared values sum to ; averaging over four entries gives variance 1. Those are the two defining properties of standardization when the original variance is nonzero.
Which values supply the mean and variance?
The arithmetic above works for any chosen group of values, but choosing the group correctly matters. In a tabular dataset, a feature is usually a column: for example, floor area measured across many homes. You calculate one mean and one variance for that column, then use them to transform each value in it. You calculate a separate pair of statistics for a different feature such as room count. Averaging floor area and room count together within one home would mix different units and would not standardize either feature across the dataset.
For example, if the room-count column were , its fitted mean and variance would be 5 and 5, as calculated above. A new home with 7 rooms would be transformed using those same statistics:
You would not recalculate the mean from the new home’s features. In a training workflow, fit the statistics on the training data and reuse them for validation, test, and later inputs; otherwise, information from held-out data can leak into preprocessing.
There is one important boundary case. If every value in a feature vector is identical, its variance and standard deviation are zero, so the formula would divide by zero. Implementations need an explicit rule for this case. In neural-network calculations, one common form adds a small positive constant inside the square root:
This makes the calculation defined when , although a constant vector then remains all zeros and cannot have variance 1. For nonconstant vectors, adding also makes the resulting variance slightly different from 1.
Later, when you study Transformer layer normalization, you’ll meet the same centre-and-scale arithmetic with a different choice of values: the features within a token representation. For now, keep the general rule in view: identify the group being normalized, compute its mean and variance, and use those statistics consistently.
Key takeaways
To normalize a feature vector using mean and variance, calculate the mean, average the squared deviations to get variance, and divide each centred entry by the standard deviation. For a nonconstant vector, the result has mean 0 and variance 1. Standardization changes centre and scale; it does not guarantee values between 0 and 1 or make a skewed distribution bell-shaped.
You have now completed the mathematical groundwork in this module. Next, you’ll create PyTorch tensors and identify their batch, sequence, and feature dimensions—skills you will use to track how data moves through a neural network.