Week 2 Assignment Cost Error

Hello,

I get this assertion error when I run the learning model. All the previous test cases have passed so I am unsure why the expected cost is different. Did anybody else run into this?

Thanks for your help!

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

~/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']}"
    130 
    131     assert type(d['w']) == np.ndarray, f"Wrong type for d['w']. {type(d['w'])} != np.ndarray"

AssertionError: Wrong values for d['costs']. [array(0.15900538)] != [array(0.69314718)]

If your previous functions pass their tests, then the bug must be in the model function. Perfectly correct functions can return bad results if you call them with incorrect parameters. Note that the costs array is returned by the optimize function. So either you passed incorrect parameters to optimize or perhaps you stored the return values in the wrong variable.

Thanks!. Is 0.15900538 is the correct expected cost? Its showing up as a expected cost in a previous test case as well

w = [[0.80956046]
 [2.0508202 ]]
b = 1.5948713189708588
dw = [[ 0.17860505]
 [-0.04840656]]
db = -0.08888460336847771
Costs = [array(0.15900538)]
All tests passed!

If you actually read the code in the failing assertion, you can see that it’s the second one that is the expected value ([array(0.69314718)])

So that suggests that you are ending up referencing costs as a global variable. So how did that happen? Carefully examine how you handle the return values from optimize.

Ah thanks! That was a bad typo :slight_smile: Appreciate the help!