Week 2 Assertion error


I would very much appreciate a bit of help with debugging this error. I have not written any of this code.

~/work/release/W2A2/public_tests.py in model_test(target)
127 assert type(d[‘costs’]) == list, f"Wrong type for d[‘costs’]. {type(d[‘costs’])} != list"
→ 128 assert len(d[‘costs’]) == 1, f"Wrong length for d[‘costs’]. {len(d[‘costs’])} != 1"
129 assert np.allclose(d[‘costs’], expected_output[‘costs’]), f"Wrong values for d[‘costs’]. {d[‘costs’]} != {expected_output[‘costs’]}"

AssertionError: Wrong length for d[‘costs’]. 20 != 1

Welcome to the community.

This is mostly caused by your hard-coding for variables, parameters and so on.
This test is actually sets the iteration count to 50, then, call model(). So, expected output for “cost” is just one length. But, if you hardcode parameters for num_iterations=2000, then, you will get 20 costs values. That’s the reason of an assertion error.

def model(X_train, Y_train, X_test, Y_test, num_iterations=2000, learning_rate=0.5, print_cost=False):

You probably misunderstood this. There are “default parameters” which are used when there is no argument passed. So, you do not need to care at all.

Hope this helps