Mean, spread and normalising
Why it matters Networks train badly when one input is in the thousands and another is near zero. Normalising puts every input on the same footing.
The mean is the average. The spread (standard deviation) is roughly how far values sit from the mean on a typical day. To normalise a column: subtract its mean, then divide by its spread. Afterwards the column has mean 0 and spread 1.
Tiny numbers
House sizes 50, 100, 150 square metres: mean 100, spread about 40.8. Normalised: about -1.22, 0, 1.22. Bedrooms 1, 2, 3: mean 2, spread about 0.82, normalised to the same -1.22, 0, 1.22. Now both inputs speak the same scale.
Standard deviation: the square root of the average squared distance from the mean. np.std computes it.
One trap: a column where every value is the same has spread 0, and dividing by 0 breaks. Leave such a column as zeros.
Recap (x - mean) / spread, per column, with a guard for spread 0.
Words and symbols in this lesson
- array
- a NumPy block of numbers, all the same type, that does maths on every item at once
- mean, spread
- the average, and roughly how far values sit from it (standard deviation)
Write normalise(X) for a 2D array: each column gets mean 0 and spread 1. A column with spread 0 becomes all zeros. No loops over rows.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.