Getting an assertion error,Need Help

Gradient at initial w, b (zeros): -1.108132775257732 -0.18136082474226803
Using X with shape (4, 1)

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

~/work/ 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 1: 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"

AssertionError: Case 1: dj_db is wrong: -0.5 != -2


Can you send me your code in a direct message and I’ll take a look.

have sent the code

Got same error for db dtype into float 64, i solved it by using ‘nanmean’. test passed.

@chiragnaik7000 I think it is simply indentation problem.

Check your identation starting from the ‘for loop’ till the return function.

1 Like

Thanks Kingsley! I had this problem too, and spent hours trying to figure out what the problem was, and when I fixed the indentation, viola! the problem went away. I think that Dr. Ng is doing a fantastic job with this course. One item that would be useful to hear a little about is how jupyter notebooks and the code within requires indentation to be ‘correct’. Before I saw your note, I had no idea that incorrect indentation would cause problems in code, and it wasn’t covered (at least I don’t remember it being covered) in any of Dr. Ng’s material to this point.