Week 3 Logistic Regression Assignment: Results Match Expected Ouptut, But Fail the Unit Test

In exercise 3 my results match the expected output, but I am failing the compute_gradient_test. I am confused by the AssertionError being thrown by the compute_gradient_test for two reasons. First, because its expected value for dj_db (0.28936094) does not match the expected output (-0.5999999999991071). Second, because the AssertionError says it evaluates to a dj_db value of 0.42250954, but my dj_db is -0.6.

My results:
dj_db at test w and b: -0.6
dj_dw at test w and b: [-44.83135361795273, -44.37384124957207]

Expected Output:
dj_db at test w and b (non-zeros) -0.5999999999991071
dj_dw at test w and b (non-zeros): [-44.8313536178, -44.37384124]

AssertionError:
Wrong value for dj_db. Expected: 0.28936094 got: 0.4225095475509334

Clearly there is something wrong with my code because I am getting these results when I run the gradient descent algorithm.

Iteration 0: Cost 0.96
Iteration 1000: Cost 2.36
Iteration 2000: Cost 2.36
Iteration 3000: Cost 2.36
Iteration 4000: Cost 2.36
Iteration 5000: Cost 2.37
Iteration 6000: Cost 2.37
Iteration 7000: Cost 2.37
Iteration 8000: Cost 2.37
Iteration 9000: Cost 2.37
Iteration 9999: Cost 2.37

Can someone please help me understand why I am getting the AssertionError, and more importantly, help me fix my gradient descent cost.

Thank you

Full code for the Exercise and AssertionError is below:

Compute and display cost and gradient with non-zero w and b

test_w = np.array([ 0.2, -0.5])
test_b = -24
dj_db, dj_dw = compute_gradient(X_train, y_train, test_w, test_b)

print(‘dj_db at test w and b:’, dj_db)
print(‘dj_dw at test w and b:’, dj_dw.tolist())

UNIT TESTS

compute_gradient_test(compute_gradient)

dj_db at test w and b: -0.6
dj_dw at test w and b: [-44.83135361795273, -44.37384124957207]

AssertionError Traceback (most recent call last)
in
8
9 # UNIT TESTS
—> 10 compute_gradient_test(compute_gradient)

~/work/public_tests.py in compute_gradient_test(target)
51 dj_db, dj_dw = target(X, y, test_w, test_b)
52
—> 53 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.4225095475509334

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]

Your code for compute_gradient() does not return the correct value for dj_db for the test that is provided in public_tests.py.

I received a similar assertion error (mine is related to z_wb = b). It’s not clear from the thread how the error was resolved.