机器学习笔记之特征缩放

来源:互联网 发布:淘宝代购售假申诉 编辑:程序博客网 时间:2024/06/17 22:41

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.

原创粉丝点击