Week 3 exercise 5

I do get a cost output but it is slightly different from the expected value. I also get an assertion error that is significantly different from the expected output.

I did the sum then multiply method and the dot method and got the same (wrong) answer.

Should I be looking at my inputs that passed previous tests or is the equation wrong?

cost = 0.6926858869721941

AssertionError Traceback (most recent call last)
3 print("cost = " + str(compute_cost(A2, t_Y)))
----> 5 compute_cost_test(compute_cost)

~/work/release/W3A1/public_tests.py in compute_cost_test(target)
126 assert type(output) == float, “Wrong type. Float expected”
→ 127 assert np.isclose(output, expected_output), f"Wrong value. Expected: {expected_output} got: {output}"
129 print("\033[92mAll tests passed!")

AssertionError: Wrong value. Expected: 0.5447066599017815 got: 1.0493608309109266

Expected output

cost = 0.6930587610394646

A difference in the 3rd decimal place is not a rounding error: it’s a real error. My guess is that means you took the sample code they gave you literally as the complete solution for the cost, but it’s not. They told you that in the instructions, although perhaps they were a bit too subtle about it. Compare the code you wrote to the mathematical formula for the cost and ask yourself two questions:

  1. What happened to the factor of \frac {1}{m}?
  2. Why is there only one term? What happened to the Y = 0 term?
1 Like