Please I need help with this error


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]]

1 Like

Maybe you hard-coded the learning rate or initializing parameters wrongly.

I used the default learning rate. the initial learning rate in the model function.

But call the previous functions into the model functions. can that result to the error?

1 Like

That is incorrect.

No. That is the correct way to implement your code: calling previous functions.

The main point here is that your code should be general enough to work for any learning rate, not just for the default learning rate or any other fixed value. Do you know how to do that?

No please

After changing my learning rate and the num_iterations, resulted into new error

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)
126
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’]}"
130

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

Now you hard-coded the number of iterations as well.
Please note that num_iterations should be num_iterations and learning_rate should be learning_rate.

Yes, the point is you should just use the parameter values that are passed in to model at the top level when you call optimize. There should be no “equal signs” in the parameters you are passing to optimize, because that would mean you are over-riding and hard-coding the values, which doesn’t work.

Also note that this is not a beginning programming course and you need to have reasonable experience with python before you start here. The way python handles “named parameters” is a bit different than some other languages, so if you are having trouble with this idea, you should google “python named parameters” and spend some time reading about how they work. They are also sometimes called “keyword parameters”, so try that search as well.