Week 2 Exercise 8 Error!

Hello all,

I have the below error when trying to run exercise 8. Anyone can help? Thank you.

The bug is not in propagate since it does not modify its inputs. The problem is you passed down objects that are the wrong shapes. The bug is in your model function: you are passing the wrong argument to your initialize routine. You use the global variable dim, which has nothing to do with the parameters that are being passed into your model function.

Sir, I am getting this error.

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

~/work/release/W2A2/public_tests.py in model_test(target)
    116 
    117     assert type(d['costs']) == list, f"Wrong type for d['costs']. {type(d['costs'])} != list"
--> 118     assert len(d['costs']) == 1, f"Wrong length for d['costs']. {len(d['costs'])} != 1"
    119     assert np.allclose(d['costs'], expected_output['costs']), f"Wrong values for d['costs']. {d['costs']} != {expected_output['costs']}"
    120 

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

What is wrong I am doing, above this exercise, every exercise shows "all tests passed "

hi @Prince_Kumar_Sah , what @paulinpaloalto mentioned is that you need to check earlier in your code. On the face of it, it looks like the input variable for the optimize function is not correct. In your first screenprint, line 36: w,b=initialize_with_zeros(dim) is not correct: dim is a global variable and needs to be replaced by a specific variable in your case. Hope this helps.

Yes, that’s definitely a problem. Once you fix that, also note that the fact that your costs array ends up the wrong length probably means you are “hard-coding” the number of iterations on the call from model to optimize, meaning that you are ignoring the actual value of the parameter being passed in at the top level to model.

1 Like

Hi,
I also got errors in week 2 exercise 8. (Passed all the previous exercises.) I did not find an answer in the discourse. I suspect errors coming from w and b. However, I did not fix the bug after trying something like params.get(" "). Could you please help me on this?

Here is the error msg:

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

~/work/submitted/courseraLearner/W2A2/public_tests.py in model_test(target)
    127     assert type(d['Y_prediction_test']) == np.ndarray, f"Wrong type for d['...
    128     assert d['Y_prediction_test'].shape == (1, x_test.shape[1]), f"Wrong sh...
--> 129     assert np.allclose(d['Y_prediction_test'], expected_output['Y_predictio...
    130 
    131     assert type(d['Y_prediction_train']) == np.ndarray, f"Wrong type for d[...

AssertionError: Wrong values for d['Y_prediction_test']. [[0. 0. 0.]] != [[1. 1. 0....

If you open the file public_tests.py and take a look at the code for model_test, you’ll find that the code checks a lot of other things first, including the shape and values of the w and b outputs. So if your predict function passed the earlier tests in the notebook, then this probably just means that you passed incorrect arguments to predict when you called it from model to generate the value Y_prediction_test. Please take a careful look at that code.

Thank you. I looked into the public_test.py file and found the error – I made some mistakes in the predict function, but it passed the test.