C1_W2 Error in Compute Gradient


I am not sure how to go about this since my code is exactly how it should be.

Hi, Caleb.

You posted this question under “General Discussion”, but you’d have better luck getting a quick answer if you post it under the category of the specialization you are taking. I’m a DLS mentor and have not taken either MLS or M4ML, but I’m guessing your question is about one of those. You can move the thread by using the little “edit pencil” on the title. Or if you prefer, just reply and give the name of the specialization and I can move it for you.

Because I don’t know this assignment, I can’t give any more specific clues, but the general thing to say is that you’re starting from the wrong point of view. If you get the wrong answer, that means you code must be incorrect. The tests here have been debugged. So the first thing to do is to check your code again with the math formulas you are trying to implement. There are two general possibilities:

  1. Your code doesn’t actually do what you intended.
  2. Your code does what you intended, but your understanding of the formulas is incorrect. Meaning that it’s your intention that is where the mistake is.

But the hope is someone who actually knows the assignment will find this thread and have more specific advice once it gets moved.

Regards,
Paul

This looks a lot like it’s from MLS C1 W2, so I’ll move it there so that one of the (many) mentors there might notice it.

If that was true, your code would return the correct values.

Hello @Caleb_Musfeldt

Let me suggest you a way to check your code. If you check out the public test script (which you can do by clicking “File” > “Open” > “public_tests.py” in the lab), you will find that the failed test actually used the following input parameters:

    x = np.array([2, 4, 6, 8]).T
    y = np.array([4, 7, 10, 13]).T + 2
    initial_w = 1.5
    initial_b = 1

You can see that it has only 4 samples so even we can compute the results by hand. Therefore, I suggest you to add a few print lines to print any intermediate values in the flow of your solution, so that you can inspect whether they are correct or not. The idea is simple, you calculate those values yourself, and compare with the printed ones. As soon as you find something not matching, you narrow down the problem to the line that produces that unmatched value.

Good luck!
Raymond