Logistic regression weights not right

Hello, I have pasted an error I have not been able to get rid of. It tells me the weights are not equal to the correct weights once I compile the whole model to but the logistic regression model but all the previous tests in the lab have been successfully tested so it shouldn’t be in anything prior. Here is the error:

1 Like

Most likely that means that you have called optimize incorrectly from model. The bug is in your model code. You must pass all the arguments to optimize, including the number of iterations and the learning rate, but you must not “hard-code” them by specifying the values in the call. Just pass through the values passed into model at the top level.

2 Likes

Oh thank you, I didn’t notice that they had changed some of the variable values in the model method call. Thanks again

1 Like

Hi Amr, have you found where the bug is? I got exactly the same error! (even the wrong values are the same!)
Thanks in advance!

Have you read my earlier response on this thread? The issues I mentioned are the first thing to check.

Thanks for reply, I have checked the both the ‘optimize’ and ‘model’ function, since I been trying to solve this bug for hours I tried many things including:
changing the num_iterations and learning_rate, but no matter what numbers I changed them to, the values for w kept the same (exactly same number as shown in the fig Amr posted)

You don’t need to assign specific values to them. Also note that just typing new code into a function and calling it again does nothing: it runs the old code. You must click “Shift-Enter” on the function cell to get the new code included.

This is my current values in the input for both functions
def optimize(w, b, X, Y, num_iterations=100, learning_rate=0.009, print_cost=False):
def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):

No, those are the definitions of those functions. So that means those are the default values that will be used if you do not pass the values. Calling a function is a completely different thing than defining a function, right? But the point is that not passing the unmodified values is a mistake: the values come from the test case, which is the top level call to model.

If you are not familiar with python and how function calls work, please realize that this course is not a beginning programming course. You need to already understand these things in order to succeed here.

1 Like

Many many thanks for your tips! I finally realize that the default values in the ‘model’ function is not passed to the ‘optimize’ function!
I’m not a python expert but I been using python for awhile… but I never thought about the default value in the model function never passed to the ‘optimize’ and this cost me hours to debug.

Glad you got it to work, but the way you phrased that still has me a bit worried. The point is that we are not using any default values here, right? We are passing through the actual values that were given in the test case and not modifying them in any way. That’s the point: we are writing general code here that works in all cases and is not “hard-coded”.

1 Like

Thanks for your kind notice, now I have deleted all the hard-coded values and just pass the variables into the function so it is now ‘general’. :grinning: