← AI / ML Foundations
10 / 25
Lesson 10 — Standardize features
Standardisation: mean 0, spread 1
Standardising a feature means: subtract the mean, then divide by the standard deviation (std) — a number that says how spread out the values are. The result is called a z-score: 0 means "exactly average", 1 means "one std above average", −1 "one below".
# std = square root of the average squared distance from the mean
heights = [160, 170, 180]
avg = sum(heights) / len(heights)
spread = (sum((h - avg) ** 2 for h in heights) / len(heights)) ** 0.5 # 8.165
Unlike min-max scaling, one extreme value does not squash everything else into a tiny range.
Why it matters: gradient descent (coming up) trains faster and more reliably when features are standardised.
Want it another way?
Task
Compute std with the formula from the theory, then the z-scores. Expected std 2.0.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.