We have constructed a way to find the “best”
m values using gradient descent! Let’s try this on the set of baseball players’ heights and weights that we saw at the beginning of the lesson.
Run the code in script.py.
This is a scatterplot of weight vs height.
We have imported your
gradient_descent() function. Call it with parameters:
Store the result in variables called
Create a list called
y_predictions. Set it to be every element of
X multiplied by
m and added to
The easiest way to do this would be a list comprehension:
new_y = [element*slope + intercept for element in y]
y_predictions on the same plot as the scatterplot.
Does the line look right?