(course 1, week 3, exercise 8) AssertionError: Wrong values for W1

I am getting AssertionError: Wrong values for W1 in the nn_model function. My output and the expected output is completely identical.

Cost after iteration 0: 0.692739
Cost after iteration 1000: 0.000218
Cost after iteration 2000: 0.000107
Cost after iteration 3000: 0.000071
Cost after iteration 4000: 0.000053
Cost after iteration 5000: 0.000042
Cost after iteration 6000: 0.000035
Cost after iteration 7000: 0.000030
Cost after iteration 8000: 0.000026
Cost after iteration 9000: 0.000023
W1 = [[-0.65848169 1.21866811]
[-0.76204273 1.39377573]
[ 0.5792005 -1.10397703]
[ 0.76773391 -1.41477129]]
b1 = [[ 0.287592 ]
[ 0.3511264 ]
[-0.2431246 ]
W2 = [[-2.45566237 -3.27042274 2.00784958 3.36773273]]
b2 = [[0.20459656]]

AssertionError Traceback (most recent call last)
7 print("b2 = " + str(parameters[“b2”]))
----> 9 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
273 assert output[“b2”].shape == expected_output[“b2”].shape, f"Wrong shape for b2."
→ 275 assert np.allclose(output[“W1”], expected_output[“W1”]), “Wrong values for W1”
276 assert np.allclose(output[“b1”], expected_output[“b1”]), “Wrong values for b1”
277 assert np.allclose(output[“W2”], expected_output[“W2”]), “Wrong values for W2”

AssertionError: Wrong values for W1


1 Like

Hi, Mukul.

Would you please try an experiment for us and see if that changes the results? Click “File → Open” to get the file explorer view of the assignment. Then delete all the “utility dot py” files, like public_tests.py, test_utils.py and so forth. Just click the check box and then click the trash can icon and confirm the dialog. Then click “Help → Lab Help → Get Latest Version”. That will replace all those files with the current (latest) version.

Once you’ve done that, please run the tests again and let us know if that changes the results or not.


Where is “Help” button that i had to click

It is in the upper right corner of the window as highlighted in this screen shot:

I also experienced the same issue even after I updated the files version. However, if I put the variables in front of the called function, i got an error “UnboundLocalError: local variable ‘parameters’ referenced before assignment”.

Would you be able to help with this?

Welcome to the community !

The error message said that you did not define “parameters” in this nn_model(). There are two possibilities.

  1. You forgot to implement one line of code above. It is to initialize “parameters”.
  2. Or, you initialize different variable, like “parameter”.

Please double check.

By the way, pasting code is not recommended. (traceback should be OK). Please remove it, thank you.

I got it working.

Thank you!

i’m having same issue cost function values are same as expected but the value of W1 is wrong i tried to run intialize parameters which also showed wrong values for W1 im using np.random.rand((a,b))*0.01. Can anybody help

That is the wrong rand function. Please have another careful look at the instructions. Notice that your values are all positive, but the expected values are both positive and negative. That’s also the wrong syntax for invoke one of the np.random functions: it is np.zeros and np.ones that take tuples as arguments.

1 Like

Thanks a lot it really helped find my error

1 Like