Getting better results than the expected output

Hello, on DLS C1W4 A2, Exercise 2 - L_layer_model, I get somehow a lower cost (0.69) than the expected output (0.77). These small differences get propagated forward on the following exercises within the Jupyter Notebook. I still got a 100% mark on the assignment, but I wanted to make you aware of this matter. The difference is most likely due to my code, but I found it odd that it was better.

Are you sure that you didn’t manually import your functions from the previous “Step by Step” exercise? Please note that the instructions do not tell you to do that and they give you an import file that has them. The key point is that they actually used a different (more sophisticated) initialization algorithm than the one we built in the previous assignment and that gives different results.

The other thing to check is that you actually ran the cell that sets layers_dims to be the 4 layer version of the network. If you don’t run that, then you end up building the 2 layer network again. Just having that cell sitting there doesn’t do anything unless it actually gets executed. I added a print statement in my L_layer_model code so that I can be sure I’ve got the correct parameters:

layers_dims = [12288, 20, 7, 5, 1]
Cost after first iteration: 0.7717493284237686
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
 All tests passed.

Here’s what I get if I use the 2 layer layers_dims:

layers_dims = (12288, 7, 1)
Cost after first iteration: 0.6950464961800915
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
 All tests passed.

Note that my cost value in that case is exactly the same as the value you show, so I’ll bet that’s what happened. If I make the other mistake (using the wrong init function but with the correct layers_dims), then I get a slightly different wrong value:

layers_dims = [12288, 20, 7, 5, 1]
Cost after first iteration: 0.6931477726958
layers_dims = (10, 5, 6, 1)
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
Error: Wrong output for variable W3.
Error: Wrong output for variable b3.
Error: Wrong output for variable 0.
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
layers_dims = (10, 5, 6, 1)
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
Error: Wrong output for variable W3.
Error: Wrong output for variable b3.
Error: Wrong output for variable 0.
 2  Tests passed
 2  Tests failed

So that would explain why you pass the grader: your code is actually correct, but you ran the test with the notebook in the wrong state.

Paul, eagle eyes. You are right, I forgot to run the cell that sets the layer_dims. Now I get the expected results!! Thanks