GradientDescent in Practice I - Feature Scaling
Note: [6:20 -The average size of a house is 1000 but 100 is accidentally written instead]
We can speed upgradient descent by having each of our input values in roughly the same range.This is because θ will descend quickly on small ranges and slowly on largeranges, and so will oscillate inefficiently down to the optimum when thevariables are very uneven.
The way toprevent this is to modify the ranges of our input variables so that they areall roughly the same. Ideally:
−1 ≤ x(i) ≤ 1
or
−0.5 ≤ x(i) ≤ 0.5
These aren'texact requirements; we are only trying to speed things up. The goal is to getall input variables into roughly one of these ranges, give or take a few.
Two techniquesto help with this are feature scaling and meannormalization. Feature scaling involves dividing the input values by therange (i.e. the maximum value minus the minimum value) of the input variable,resulting in a new range of just 1. Mean normalization involves subtracting theaverage value for an input variable from the values for that input variableresulting in a new average value for the input variable of just zero. Toimplement both of these techniques, adjust your input values as shown in thisformula:
xi:=(xi−μi)/si
Where μi isthe average of all the values for feature (i) and si is therange of values (max - min), or si is thestandard deviation.
Note thatdividing by the range, or dividing by the standard deviation, give differentresults. The quizzes in this course use range - the programming exercises usestandard deviation.
For example,if xi represents housing prices with arange of 100 to 2000 and a mean value of 1000, then, xi:=(price−1000)/1900.