In the Exercise 2 of this lab, I was asked to implement the compute_cost function for gradient descent, and in the solution I need to calculate the loss function, here’s two different implementation that I have tried:
{image removed by moderator as it contained codes from grader cell and posting on public post thread is against community guidelines}
Content in read rectangle is my code which cause the Exercise 5 with following exception:
You aren’t supposed to post solutions, a mentor will likely ask you to remove it, or do so for you
Upon casual inspection it appears to me that the two expressions you wrote are not mathematically equivalent, which you could prove or disprove by printing out intermediate values as you iterate on i. If the values are different, look at the constituent terms to see what was omitted in the version that doesn’t pass the test. Let us know what you find.
Sorry, I already remove some sensitive information relative to the solution and only leave information which is necessary.
After digging into the testing code I finally figure out why, it turns out that the label y are been initialized to y = np.array([0.5] * 8) in public_tests.py, and I assume every label y either has 1 or 0, so it cause the issue. But I remember for the logistics regression the label y is always 0 or 1, why the testing code use these kind of data that not match this rule?
as mentioned by the other mentor kindly remove the codes.
Did you calculate the total cost, which is 1/m of the loss_sum you calculated. and make sure you calculate total loss outside of the loop created for each training example.
See the below image.
necessary information related to your grade cell would be your error output.
if a mentor wants to have a look at your codes, they will ask for it, until then kindly refrain from posting grade cell codes as it is against Code of Conduct.
Yes I calculated the total cost. I already figure out why my code can’t pass the test as I mentioned above.
Now my question is, I remember for the logistics regression the label y is always 0 or 1, why the testing code use these kind of data that not match this rule?