Planar_data_classification_with_one_hidden_layer Excercise 8 error

The cost value is going up from first iterations and than it turns in to nan after a few hundreds of iterations . I would appreciate any help. Restarting of the kernel did not help.

Cost after iteration 0: 0.693198
Cost after iteration 1000: nan
Cost after iteration 2000: nan
Cost after iteration 3000: nan
Cost after iteration 4000: nan
Cost after iteration 5000: nan
Cost after iteration 6000: nan
Cost after iteration 7000: nan
Cost after iteration 8000: nan
Cost after iteration 9000: nan
W1 = [[ -16151.48761099 40094.87691492]
[-360708.80502007 896694.73776285]
[ 17194.29194027 -42664.68066471]
[ 209432.69985165 -519775.95648378]]
b1 = [[ -9454.14941358]
[ 10053.6841467 ]
[ 122511.81043522]]
W2 = [[ -9.46131057 -211.85626202 10.08675527 122.71208997]]
b2 = [[1998.68544]]

AssertionError Traceback (most recent call last)
----> 1 nn_model_test(nn_model)

~/work/release/W3A1/ in nn_model_test(target)
292 assert output[“b2”].shape == expected_output[“b2”].shape, f"Wrong shape for b2."
→ 294 assert np.allclose(output[“W1”], expected_output[“W1”]), “Wrong values for W1”
295 assert np.allclose(output[“b1”], expected_output[“b1”]), “Wrong values for b1”
296 assert np.allclose(output[“W2”], expected_output[“W2”]), “Wrong values for W2”

AssertionError: Wrong values for W1

Expected output

Cost after iteration 0: 0.693198
Cost after iteration 1000: 0.000219
Cost after iteration 2000: 0.000108

Cost after iteration 8000: 0.000027
Cost after iteration 9000: 0.000024
W1 = [[ 0.56305445 -1.03925886]
[ 0.7345426 -1.36286875]
[-0.72533346 1.33753027]
[ 0.74757629 -1.38274074]]
b1 = [[-0.22240654]
[ 0.33663708]
W2 = [[ 1.82196893 3.09657075 -2.98193564 3.19946508]]
b2 = [[0.21344644]]
All tests passed!
All tests passed.

Restarting the kernel won’t help if your code is wrong. I’m guessing that your “update parameters” logic is incorrect. Are you perhaps adding instead of subtracting?

Thank you for your reply. Generally I have got all right values and all test passed signs on all previous exercises. I tried to play with other parts of the code including update parameters part but with no clear outcome. I am not sure how to hunt the error in most efficient way. I can think only about going through each step manually, which might take some time.

Here is my outcome from Update parameters part:
W1 = [[-0.00643025 0.01936718] [-0.02410458 0.03978052] [-0.01653973 -0.02096177] [ 0.01046864 -0.05990141]] b1 = [[-1.02420756e-06] [ 1.27373948e-05] [ 8.32996807e-07] [-3.20136836e-06]] W2 = [[-0.01041081 -0.04463285 0.01758031 0.04747113]] b2 = [[0.00010457]] All tests passed!

Expected output

W1 = [[-0.00643025  0.01936718]
 [-0.02410458  0.03978052]
 [-0.01653973 -0.02096177]
 [ 0.01046864 -0.05990141]]
b1 = [[-1.02420756e-06]
 [ 1.27373948e-05]
 [ 8.32996807e-07]
W2 = [[-0.01041081 -0.04463285  0.01758031  0.04747113]]
b2 = [[0.00010457]]
All tests passed!
 All tests passed.

Hi Sergiy,

You are very true. Finding mistakes is not that easy :slight_smile:

I suggest you to create a cell below the cell and try working on each of the codes, you have modified step-by-step. This will lead you to your goal.
Its a friendly suggestion though, not a professional one. You need to have that eye of a programmer that hunts out for every code in a specific manner.


Hey @Sergiy_Tokar,
Welcome to the community. I agree with what @Rashmi says. Still, if you find difficulty in finding the issue, feel free to share your code with any of the mentors, since the issue is something that the test cases are unable to catch. Make sure to DM your code to one of the mentors, and not post it here publicly, since it is against the community guidelines.


All cells are working fine but I got this. Can anyone help me out with this?

@Sergiy_Tokar It will be helpful if anyone of you help me out with this.

Hello, Shubhangi.

Welcome to the community.

Please check the earlier cell carrying the Graded function on “nn_model”. You might have used any global variables or would have missed any important component within the equations, which is throwing an error in the test model.

Also, after making the changes, try saving it and run all the cells from the beginning to get the right outcome. Let us see if that works for you!