Week 2 exercise 8 question help


Logistic Regression with a Neural Network Mindset _ Coursera - Chrome 2023-08-31 오후 3_19_20 (2)

Moderator Edit: Solution Code Removed

I don’t know what’s the matter…
How do I solve this problem??

Does your propagate() function pass all its tests?

1 Like

yes. All other before 8 test passed !!

You hard-coded the values of num_iterations to 2000 and learning_rate to 0.5 when you call optimize function inside the model function. But the test function uses different values.

3 Likes

oh I solved it, thank you for your advice
I used iterations and learning rate same with optimize function, 100,0.009
But another problem occurs again
They say “Wrong values for d[‘w’]”
Does it mean dimension of w is wrong??

1 Like

It means values are wrong, not dimension. I just noticed that in your code, you initialize the w and b but then you did not grab the updated w and b from the params dictionary. Check the below step:

# Retrieve parameters w and b from dictionary "params"
    # w = ...
    # b = ...

Actually, I added

w=params[“w”]
b=params[“b”]

codes after posting this question, but still doesn’t work…

What is the meaning of params?
Does is a function that I made or something like library?

Please share full error.

params -- dictionary containing the weights w and bias b

Check optimize function for more details to understand about params

this is the error code!!

2 Likes

Where are you adding these? It should be after the optimize function and before the predict function. If you are doing it correctly, and passed all the above tests, then send me your code of model function in a private message. Click my name and message.

That is just a different form of “hard-coding”. You are missing Saif’s point: you should be using the actual values that are passed into model at the top level by the test case. If you use different values that what they are requesting, then you get a different answer, right? That is what is causing your error.

1 Like

No, don’t do that either.
Use the variable names - do not set a specific value.

1 Like

I am getting the exact same error and all my previous functions work! How can I fix it? This is my code

{moderator edit - solution code removed}

Notice that you do not pass the values of learning rate and number of iterations when you call optimize. So think about what that means: what values will actually end up being used? Not the ones that were passed in to model at the top level, right? That’s why it fails.

Yes, I already fix it! Thank you anyways for your response.

If I use 2000, 0.5 then the error code says
'Wrong length for d[‘costs’]. 20! = 1

How can I fix this?

This is still incorrect. You should do the general code (not hard-coded) which can work for any value, not just 2000 and 0.5.

yes, so if I changed them to 100,0.009, still doesn’t work.
And I sent you my full code by message.
Can you check it for me?