The practice assignment: correct output once but not passing public test cases

  1. To calculate cost: **I get the correct cost on the mentioned test case with **
    initial_w = 2
    initial_b = 1

However, on the public test cases I get the error:
AssertionError: Case 1: Cost must be 0 for a perfect prediction but got 12.134178884999997

  1. To calculate gradient, again I get the correct outputs, but fails on more test cases.

~/work/public_tests.py in compute_gradient_test(target)
50 dj_dw, dj_db = target(x, y, initial_w, initial_b)
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

AssertionError: Case 1: dj_db is wrong: -2.0 != 0.0

I don’t know if I’m allowed to paste my code here and ask for help

Hi @Aakanksha_Agrawal,

You may check out the public test by clicking “File” > “Open”, then click “public_tests.py”, and you will be able to see the w and b values used for case 1 in compute_cost, and the same idea to find the test case input for compute_gradient.

You see that the test cases only use a few data points, so actually it’s completely possible for us to inspect our work by walking through the code with those data points in mind or on paper. For example, the error suggests that Cost must be 0 for a perfect prediction but got 12.134178884999997. In this case, you need to find out why it is not 0 if the initial w and b constitute a perfect model.

Being able to debug oursevles is pretty important in data science because we need to code.

Good luck!

Raymond

PS: we can’t post assignment code here.

Hi @rmwkwok ,

I see. Yep that makes sense, i’ll proceed as per your advice.

PS: we can’t post assignment code here.
thought so, I shall not.

Thanks for your help, and also the super quick reply.

Best,
Aakanksha

1 Like