MLS Course 1 W3 Practice Lab Exercise 2

I have a problem with course 1 week 3 practice lab, exercise 2. My output does not match the expected output. Can anyone help, please?


Hello @Ayse_Nehir_Cevik Welcome to the community!
In your problem, Firstly you should have to complete the code of compute_cost function perfectly. Like summation of cost for all training example and divide by training sample (m).
Here use the equations to complete the compute_cost function:
𝑙𝑜𝑠𝑠(𝑓𝐰,𝑏(𝐱(𝑖)),𝑦(𝑖)) = (−𝑦(𝑖)log(𝑓𝐰,𝑏(𝐱(𝑖)))−(1−𝑦(𝑖))log(1−𝑓𝐰,𝑏(𝐱(𝑖)))
𝑓𝐰,𝑏(𝐱(𝑖)) = 𝑔(𝐰⋅𝐱(𝐢)+𝑏), where g is the sigmoid function

Initialize loss equal to zero
for ith training example to total training example:
𝑓𝐰,𝑏(𝐱(𝑖)) = 𝑔(𝐰⋅𝐱(𝐢)+𝑏) [for multiply use function]
𝑙𝑜𝑠𝑠(𝑓𝐰,𝑏(𝐱(𝑖)),𝑦(𝑖)) += (−𝑦(𝑖)log(𝑓𝐰,𝑏(𝐱(𝑖)))−(1−𝑦(𝑖))log(1−𝑓𝐰,𝑏(𝐱(𝑖)))
return cost/m

Hi! Thanks a lot for your help! I tried to code as I can the way you wrote. But unfortunately, the output is still not right. I assume I have done something wrong in the code.