Week2 - assignment 2 - ex8

I have this error when I running my code, is there anyone who can help me?

AssertionError                            Traceback (most recent call last)
<ipython-input-22-9408a3dffbf6> in <module>
      1 from public_tests import *
      2 
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
    121     assert type(d['w']) == np.ndarray, f"Wrong type for d['w']. {type(d['w'])} != np.ndarray"
    122     assert d['w'].shape == (X.shape[0], 1), f"Wrong shape for d['w']. {d['w'].shape} != {(X.shape[0], 1)}"
--> 123     assert np.allclose(d['w'], expected_output['w']), f"Wrong values for d['w']. {d['w']} != {expected_output['w']}"
    124 
    125     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]]

Hi, I faced the same issue but while debugging I noticed that I was not passing the new num_iterations, learning_rate and print_cost parameters from the “model” function to the call to “optimize” function.
So it ended up using the default values for these variables.

I am guessing you did the same since our error values are matching.

2 Likes

Thanks, Sushant! Yes, that’s one pretty common error on this function. You can’t just “copy/paste” the definition of the optimize function as the invocation of it. If you do that, you end up “hard-coding” the values of number of iterations, learning rate and the print flag, so that the results never change.

Calling a function is very different than defining a function.