4.4 - Compute the Cost DLS.C1W3

Hello

I am getting the error in Compute Cost in ‘Planar Data Classification’ assignment
I am getting below error
AssertionError Traceback (most recent call last)
in
3 print("cost = " + str(compute_cost(A2, t_Y)))
4
----> 5 compute_cost_test(compute_cost)

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

AssertionError: Wrong value. Expected: 0.5447066599017815 got: 1.0493608309109266
I used the formula

logprobs = np.multiply(np.log(A2),Y)
cost = - np.sum(logprobs)
Can someone help here?

That is not the complete solution. Compare that to the math formula for the cost and ask yourself two questions:

  1. What happened to the factor of 1/m?
  2. Why is there only one term? What happened to the Y = 0 term?

They just give you a hint about how to code this using dot product in the instructions. If you read what they said carefully, you’ll see they are telling you that is not all you need to do.

Thank you for pointing it out. I should use the Cross entropy formula for binary classification
Now i corrected my code and its error free.

Regards
Abhishek