Course1 neural networks and deep learning week2 assignment exercise 8 problem

{moderator edit - solution code removed}


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

~/work/release/W2A2/public_tests.py in model_test(target)
    141     assert type(d['Y_prediction_train']) == np.ndarray, f"Wrong type for d['Y_prediction_train']. {type(d['Y_prediction_train'])} != np.ndarray"
    142     assert d['Y_prediction_train'].shape == (1, X.shape[1]), f"Wrong shape for d['Y_prediction_train']. {d['Y_prediction_train'].shape} != {(1, X.shape[1])}"
--> 143     assert np.allclose(d['Y_prediction_train'], expected_output['Y_prediction_train']), f"Wrong values for d['Y_prediction_train']. {d['Y_prediction_train']} != {expected_output['Y_prediction_train']}"
    144 
    145     print('\033[92mAll tests passed!')

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

hi, I’m encountering this problem and have no idea how to fix it. Previous exercises’ tests have all passed but for this one I think I’m writing it correctly but still got the training wrong. I’d really appreciate if anyone could help this out. Thanks!

If this doesn’t help, please click my name and message your notebook as an attachment.

Do move your post to the correct topic instead of AI discussions.

I have used the little “edit pencil” on the title to move your thread to the relevant Course Q&A category.

I agree your code looks correct, although please note that we aren’t supposed to show our solution code in public like this. I’ll edit your post to remove it.

One possible issue here is that you’ve typed corrections into the code, but after doing that you did not click “Shift-Enter” on the actual function cell. Instead you just ran the test again, which ends up calling the previous version of the model function before your latest changes. One easy way to make sure everything is in sync and WYSIWYG (meaning you are running the actual code that you are looking at) is to do this sequence:

Kernel -> Restart and Clear Output
Save
Cell -> Run All

My suggestion is to try that as the next step and see what happens. If it still fails, then my next theory is that there is actually something wrong in your predict function cell.

Please try the above and let us know what happens.