Skip to Content
Learn
Linear Regression
Use Your Functions on Real Data

We have constructed a way to find the “best” b and 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.

Instructions

1.

Run the code in script.py.

This is a scatterplot of weight vs height.

2.

We have imported your gradient_descent() function. Call it with parameters:

  • X
  • y
  • num_iterations of 1000
  • learning_rate of 0.0001

Store the result in variables called b and m.

3.

Create a list called y_predictions. Set it to be every element of X multiplied by m and added to b.

The easiest way to do this would be a list comprehension:

new_y = [element*slope + intercept for element in y]
4.

Plot X vs y_predictions on the same plot as the scatterplot.

Does the line look right?

Folder Icon

Sign up to start coding

Already have an account?