C1_W2_Linear_Regression , Compute_Gradient

{moderator edit: image of code removed}


I am not able to understand what the error actually is & any explanation will be highly appreciated , to be mentioned i’am new to python programming.

Please do not post your code on the forum. That’s not allowed by the Code of Conduct.
If a mentor needs to see your code, we’ll contact you with instructions.

Hint: Part of your last two lines of code are incorrect.

image

1 Like

I am having a similar error computing the gradient and I’m hoping for further clarification.

I am receiving an assertion error, which as I understand relates to an operator/command not a value. I’ve pasted the error returned below:

AssertionError Traceback (most recent call last)
in
6 print(‘Gradient at initial w, b (zeros):’, tmp_dj_dw, tmp_dj_db)
7
----> 8 compute_gradient_test(compute_gradient)

~/work/public_tests.py in compute_gradient_test(target)
60 dj_dw, dj_db = target(x, y, initial_w, initial_b)
61 #assert dj_dw.shape == initial_w.shape, f"Wrong shape for dj_dw. {dj_dw} != {initial_w.shape}"
—> 62 assert dj_db == -2, f"Case 2: dj_db is wrong: {dj_db} != -2"
63 assert np.allclose(dj_dw, -10.0), f"Case 1: dj_dw is wrong: {dj_dw} != -10.0"
64

AssertionError: Case 2: dj_db is wrong: -12.0 != -2

Could I have messed up the array? Its shape is (4,1) and I believe it should only be (4, )

Thanks in advance.

The error means that your code in compute_gradient() is computing the wrong value for dj_db.

Your code returned -12.0, the expected value was -2.

The assert with the arrow and indentation (in this case it’s marked as line 62) is the one that was triggered:

An error about the size or shape of dj_dw would have been triggered by line 61.

Hi @Caroline3,

The error is telling you that your value for dj_db is not what was expected - that your compute_gradient function is returning -12 instead of the expected value of -2.

Go back and check your implementation for compute_gradient and see if you can spot what’s wrong and why it is returning -12. You might want to add some print statements temporarily to see what values it is calculating vs what you would expect.

Check the description just above the compute_gradient carefully to understand what calculations your code should make. If you’re still stuck, try clicking on the green “Click for hints” immediately after the compute_gradient cell. The first level will give you general hints, as well as some blue links you can click into to get more and more detailed hints.

Thank you for your detailed explanation of the error, I was able to find my mistake (a typo in my code) and fix it. While I feel confident in my calculus skills, I am new to Python and learning to interpret the error messages. Thanks!