Week 3 - Exercise 5 - Assertion Error wrong value


For exercise 5, I got the same cost as in the expected output. However, I am still getting the error shown in the screenshot below. What could be the problem?

That value may look close, but it’s actually incorrect. It most likely means that you took the sample code they gave you as the complete solution, but it’s not. They actually said that in the instructions, but apparently they were a little too subtle about it. :nerd_face:

Compare that code to the mathematical formula for the cost shown just above 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?

Hi, @H_Haneya. Not sure what is going on here other than you are not passing the unit test, which means something is amiss with your expression(s) for cost. That is the only task in the exercise. As the instructions indicate, there are a couple of options here:

  1. You can use np.multiply() to compute an expression for logprobs = .... The you apply np.sum() to that result remembering to multiply by (1/m), i.e. cost is an “average cost.”, to fill out cost = ...
  2. Alternatively, you can go for a one-liner for cost that applies the np.dot() function to take the required dot products which will multiply and sum-up in one go. With this option, one must be sure to make the necessary transposes so that the inner product dimensions agree. If one has an array, say X, of dimension (1, m), and another (Y) of the same dimension (1, m), the inner dimensions of the dot product X \cdot Y will be m and 1. That will not work.

Apparently, @paulinpaloalto has the inside scoop on this. When does he not? :smiley:

Found an error in my cost function.

Thank you @kenb and @paulinpaloalto for the help!

I divided the logprobs by ‘m’ in the second line of code but still, it gives an error. please help

Hi @Abdul_Samad5 ,

Please post a fresh query of the problem you have experienced, together with error messages to help diagnose what the issue might be.

Note that the factor of \frac {1}{m} was only one of the questions I posed in my earlier reply.