Showing Assertion error

Compute and display gradient with w initialized to zeroes

initial_w = 0
initial_b = 0

tmp_dj_dw, tmp_dj_db = compute_gradient(x_train, y_train, initial_w, initial_b)
print(‘Gradient at initial w, b (zeros):’, tmp_dj_dw, tmp_dj_db)

compute_gradient_test(compute_gradient)

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

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)
51 #assert dj_dw.shape == initial_w.shape, f"Wrong shape for dj_dw. {dj_dw} != {initial_w.shape}"
52 assert dj_db == 0.0, f"Case 1: dj_db is wrong: {dj_db} != 0.0"
—> 53 assert np.allclose(dj_dw, 0), f"Case 1: dj_dw is wrong: {dj_dw} != [[0.0]]"
54
55 # Case 2

AssertionError: Case 1: dj_dw is wrong: 2.0 != [[0.0]]
How to rectify the code without the assertion error?

Hi @Sarass_Chandra89

welcome to community …this is your first post

This error is because the implementation of function compute_gradient … dj_db , dj_dw , and f_wb are variables not arrays or lists so the error say that you make the dj_db , dj_dw , and f_wb lists and it isn’t correct as they are used to update w and b weights.

Note also you can check the hint

please feel free to ask any questions,
Thanks!
Abdelrahman

1 Like