At each step, we know how to calculate the gradient and move in that direction with a step size proportional to our learning rate. Now, we want to make these steps until we reach convergence.
We have all of the functions we have defined throughout the lesson.
Now, let’s create a function called
gradient_descent() that takes in
learning_rate, and a
For now, return
In the function
gradient_descent(), create variables
m and set them both to zero for our initial guess.
m from the function.
step_gradient() function to take in the parameter
learning_rate (as the last parameter) and replace the
0.01s in the calculations of
Let’s go back and finish the
Create a loop that runs
num_iterations times. At each step, it should:
- Update the values of
mwith the values
Outside of the function, uncomment the line that calls
revenue, with a learning rate of
It stores the results in variables called
Uncomment the lines that will plot the result to the browser.