标签:param tar dict ace 技术 hang -- cgi net
Consider the following 5 point synthetic data set:
Which is plotted below:
Now that we’ve computed the regression line using a closed form solution let’s do it again but with gradient descent.
Recall that:
We will need a starting value for the slope and intercept, a step_size and a tolerance
In each step of the gradient descent we will do the following:
1. Compute the predicted values given the current slope and intercept
2. Compute the prediction errors (prediction - Y)
3. Update the intercept:
4. Update the slope:
5. Compute the magnitude of the gradient
6. Check for convergence
First step:
Intercept = 0
Slope = 0
1. predictions = [0, 0, 0, 0, 0]
2. errors = [-1, -3, -7, -13, -21]
3. update Intercept
4. update Slope
5. magnitude = sqrt(( -45)^2 + (-140)^2) = 147.05
6. magnitude > tolerance: not converged
Second step:
Intercept = 2.25
Slope = 7
1. predictions = [2.25, 9.25, 16.25, 23.25, 30.25]
2. errors = [1.25, 6.35, 9.25, 10.25, 9.25]
3. update Intercept
4. update Slope
5. magnitude = sqrt((36.25)^2 + (92.5)^2) = 99.35
6. magnitude > tolerance: not converged
Third step:
Intercept = 0.4375
Slope = 2.375
1. predictions = [0.4375, 2.8125, 5.1875, 7.5625, 9.9375]
2. errors = [-0.5625, -0.1875, -1.8125, -5.4375, -11.0625]
3. update Intercept
4. update Slope
5. magnitude = sqrt(( -19.0625)^2 + (-64.375)^2) = 67.13806
6. magnitude > tolerance: not converged
Let’s skip forward a few steps… after the 77th step we have gradient magnitude 0.0107.
78th Step:
Intercept = -0.9937
Slope = 4.9978
1. predictions = [-0.99374, 4.00406, 9.00187, 13.99967, 18.99748]
2. errors = [-1.99374, 1.00406, 2.00187, 0.99967, -2.00252]
3. update Intercept
4. update Slope
5. magnitude = sqrt[()^2 + ()^2] = 0.0098992
6. magnitude < tolerance: converged!
Final slope: -0.994
Final Intercept: 4.998
If you continue you will get to (-1, 5) but at this point the change in RSS (our cost) is negligible.
After the first step we have this line:
After the second step we have this line:
After the third step we have this line:
And after the final step we have this line:
标签:param tar dict ace 技术 hang -- cgi net
原文地址:http://www.cnblogs.com/whisper-yi/p/6067453.html