Help request for C2_W3_Assignment compute_cost

Hello everyone,

I’ve been trying to pass one unit test, I’ve tried many implementation to calculate cost correctly however I couldn’t achieve and didn’t understand where is the error.

And because my compute_cost method isn’t working correctly, nn_model is also not working correctly.

Any help would be appreciated!

Hey there!

Using np.mean is technically correct. As a matter of fact, I also used this method in my first implementation. However, in this notebook, you should sum it and divide it by m like the formula, to get the score. (a little peculiar)

If it did not still work, use np.multiply in the calculation of your logloss function.

Hope that it fixes your problem.

Hey @ParetoFront !

Thank you for your answer. Unfortunately, I still get the same result:

before using np.multiply I also tried (-1/m) * np.sum(logloss)

Hi @TalhaOkur ,

Try refreshing the kernel and rerun the code from start. That would ensure your execution environment is up-to-date.

From the menu bar on top of your notebook:

Kernel ->restart and clear all output
Cell → run all above

1 Like

Hi @Kic
I’ve tried restarting kernel several times but unfortunately I still get the same result.

Dear @TalhaOkur

Which parts of the exercise is your grade not complete, i.e., which parts does the grader not give you full score?

Additionally, sometimes, an incomplete grade stems from issues from previous cells.

Could you please also check your previous cells (maybe cross referencing your answers with previous notebooks like C2_W3_Lab_2_Classification_with_Perceptron.ipynb would give you a better idea)

1 Like

Hi @ParetoFront

I changed the cost function to make it the same with the exercise you mentioned (with updating variable names), restarted the kernel, run all the previous cells, but I got the same result from the unit test. However with this version of my assignment, run all the cells and submitted it again, it passed. I don’t now where was the error but I am so happy that I finally be able to finish the assignment. Thank you so much for your help! :grinning:

And also thank you too @Kic ! :grinning:

1 Like

Glad I could help :wink:

I did the same as @TalhaOkur but I am still receiving error due to the difference in decimal but I don’t know what might be wrong

Hi, follow the log loss equation given. You need to use np.sum first and then np.multiply (look at the log loss equation) under “cost” to get the desired number.

I am also getting stuck on a decimal offset (code snippet and image below). Is anyone else experiencing this still?

image

@Matt5129 I think you suggested to do the sum first and I tried that, but I get the same result.

image

Hey, within the logloss equation, i used just “*” to multiply instead of np.multiply

I used np.multiply only in the cost equation in the second part

I hope you managed to fix this, but for others that have the same issue. I noticed your cost was 0.7054… but the expected cost was 0.6931… Check your "initialize_parameters" function and make sure you initialized your W1 and W2 by multiplying them with 0.01. Look at the instruction right about that function. This will still pass the grader, but will fail here where your cost is marginally miscalculated due to the incorrect initialization.

1 Like

Thanks, man! I didn’t understand what I was missing until you mentioned that.