Logistic regression with neural network mindset - wrong parameters in final model

Hello, I get the following error on exercise 8 of the Logistic Regression with a Neural Network mindset task. My understanding is that when model_test runs this test, it is using some hypothetical data which I do not have access to. My code works, but I end up with training accuracy of 68% and test accuracy of 34%. I then find that when I plot the cost function over iterations, nothing gets plotted. Do you have any idea what could be going wrong?

AssertionError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
132 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
→ 133 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
134
135 assert np.allclose(d[‘b’], expected_output[‘b’]), f"Wrong values for d[‘b’]. {d[‘b’]} != {expected_output[‘b’]}"

AssertionError: Wrong values for d[‘w’]. [[ 0.14449502]
[-0.1429235 ]
[-0.19867517]
[ 0.21265053]] != [[ 0.08639757]
[-0.08231268]
[-0.11798927]
[ 0.12866053]]

Are you using initialize_with_zeros function to initialize the parameters?

This suggests your code does not work. Maybe it runs without throwing any errors, but there is a problem.

What is shown in your cost history table during training?
image

My guess is that you hard-coded the learning rate when you called optimize from model. You should just be passing through the parameters that were passed in to model at the top level. If you omit the learning rate on that call, it’s also another form of hard-coding, since you’ll end up using the default declared in the definition of the optimize function.

1 Like

Also those numbers are way wrong, as you can see from looking at Tom’s output. In fact, I think those are what you get if you “scramble” the training data by doing the “flatten” operation incorrectly. Are you sure that you don’t get any errors from that section of the notebook? It’s one of the early sections before the real functions start.

Thanks everyone! Yes indeed I had hard-coded the the optimize function and it is now working.

Same error but I fixed by correcting how I called the optimize inside the model function.

{mentor edit - code removed}