Trouble with Programming Assignment: Week 2 practice lab: Linear regression

I faced an issue in Exercise 2 where we have to complete the compute_gradient function.

I followed the hints provided. However, i got an error when i run the cells to check the implementation of the compute_gradient function with two different initializations of the parameters w,b.

Here is the screenshot of the error.

Can anyone help guide me through how to resolve it?

@Zen_Liu_Zhanhong unfortunately I don’t have access to the notebook for this course, but rather than your code explicitly being incorrect, it is suggesting the way you are calculating (at least) your gradient of b is wrong/not producing the expected result. I would take a closer look at the formula you are using to do this.

2 Likes

Try to closely look at your implementation of the compute_gradient function. Use the hints. Make sure that m (number of training samples) is defined correctly, not hard-coded and that your loop follows the equations given in the notebook.

2 Likes

thanks everyone for your suggestion. i figured out what was the error. I indented 1 line of code wrongly and it got run as part of the for loop thus resulting in the error for gradient of
b. silly me. thanks once again for the prompt response!

2 Likes