Week 2 assignment: Error with model_test(model)

Hello, I got an error when I ran this code at the last part:

from public_tests import *


I got this error:

AssertionError                            Traceback (most recent call last)
<ipython-input-231-9408a3dffbf6> in <module>
      1 from public_tests import *
----> 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']}"
    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.21265053]] != [[ 0.08639757]
 [ 0.12866053]]

Although all the previous cells have passed the test. Any advice?

And when I ran this line:
logistic_regression_model = model(train_set_x, train_set_y, test_set_x, test_set_y, num_iterations=2000, learning_rate=0.005, print_cost=True)

I got:

train accuracy: 68.42105263157895 %
test accuracy: 34.0 %

If you have not already found the solution, one common cause of this type of error is “hard-coding” some or all of the parameters when you call optimize from model. That means you are ignoring the actual values for the learning rate and number of iterations (for example) that are passed in at the top level to the model function.

1 Like