C1_W3_Logistic_Regression_error in output

Cell Output OK

Compute and display gradient with w and b initialized to zeros

initial_w = np.zeros(n)
initial_b = 0.

dj_db, dj_dw = compute_gradient(X_train, y_train, initial_w, initial_b)
print(f’dj_db at initial w and b (zeros):{dj_db}’ )
print(f’dj_dw at initial w and b (zeros):{dj_dw.tolist()}’ )
dj_db at initial w and b (zeros):-0.1
dj_dw at initial w and b (zeros):[-12.00921658929115, -11.262842205513591]

It matches expected output but

in the next cell the code produces error

assert np.isclose(dj_db, 0.28936094), f"Wrong value for dj_db. Expected: {0.28936094} got: {dj_db}" 54 assert dj_dw.shape == test_w.shape, f"Wrong shape for dj_dw. Expected: {test_w.shape} got: {dj_dw.shape}" 55 assert np.allclose(dj_dw, [-0.11999166, 0.41498775, -0.71968405]), f"Wrong values for dj_dw. Got: {dj_dw}" AssertionError: Wrong value for dj_db. Expected: 0.28936094 got: 0.2017053001698443

Expected Output:

dj_db at test w and b (non-zeros) -0.5999999999991071
dj_dw at test w and b (non-zeros): [-44.8313536178737957, -44.37384124953978]

Let me know where I am going wrong

There is an error in your compute_gradient() function.

There are several tests - the ones in the notebook, which give the printed outputs and should match the “Expected Output” values.

But there are other tests - invoked by the compute_gradient_test() function. Those testss are the ones that generate the assert. That tests uses different values and conditions than the tests built into the notebook.

Also, please use a screen capture image to report errors. A text copy-and-paste often removes important formatting information, which makes the asserts difficult to interpret.


Here is the screenshot error! I am aware that there is a problem in compute_gradient(X, y, w, b, *argv):
Let me know which part of code is giving the problem for test_w and test_b which are non zeros

There is a problem in how your code computes the dj_db value for the tests used by compute_gradient_test().

You can open the public_tests.py file (from the notebook’s File menu), and see what data the test is using. For example, this test uses three features.