Week 4 Assignment 2 test not passing but output is correct

Hello, I’ve completed assigment 2 of week 4. My code seems correct as the 2 layer model training produces the correct Cost after iteration 2499: 0.04421498215868956 and correctly predicts the testing data at 72%. But I get the following error message:

Cost after iteration 1: 0.6926114346158595
Cost after first iteration: 0.693049735659989
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 1: 0.6915746967050506
Cost after iteration 2: 0.6899956541494738
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
3 Tests passed
1 Tests failed
I don’t think I’m supposed to paste code here but I can’t seem to find the solution myself and if the code works perfectly I’m at a loss how to fix a problem that seemingly doesn’t exist. Additionally, I’m having the same problem for the 4 layer model, although, my code matches the subsequent training Cost after iteration 2499 and Prediction of 80% perfectly. How is this possible? Thanks

There must be something wrong with your code. The cost value is a pretty low resolution metric for correctness. You can examine the “expected” correct values by opening the file public_tests.py and looking at the relevant test cases. Then print your W1, W2 and so forth and compare.

One thing to check: I hope that you did not “copy/paste” over your functions from the Step by Step exercise here. If so, that is a mistake: they provide you with imported versions of those functions. That mistake should not impact the results of your two_layer_model, but it would change the results in the L layer case. Meaning that there is also some logic mistake in your two layer case.

1 Like