Error in compute cost with regularization test

From Coursera Forum - Course 2 Week 1

Error in compute_cost_with_regularization_test(compute_cost_with_regularization) test

-ARAishvarya Raman

a day ago

Hi All,

I am getting error in the output of compute_cost_with_regularization_test(compute_cost_with_regularization)

The output is displayed as follows:

cost = 1.8433386503250353
Error: Wrong output
1 Tests passed
1 Tests failed
---------------------------------------------------------------------------AssertionError Traceback (most recent call last)
in 3 print("cost = " + str(cost)) 4
----> 5 compute_cost_with_regularization_test(compute_cost_with_regularization)

~/work/release/W1A2/ in compute_cost_with_regularization_test(target) 30 ]
—> 32 single_test(test_cases, target) 33
34 def backward_propagation_with_regularization_test(target):

~/work/release/W1A2/ in single_test(test_cases, target) 118 print(’\033[92m’, success," Tests passed") 119 print(’\033[91m’, len(test_cases) - success, " Tests failed")–> 120 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format( 121
122 def multiple_test(test_cases, target):

AssertionError: Not all tests were passed for compute_cost_with_regularization. Check your equations and avoid using global variables inside the function.

Also, I am not able to edit that particular cell, though I have edited that function still I am not able to understand why am I getting that particular error.

My Response:

S​ame here. Still trying to figure out what I’m doing wrong. Seems like you square, then sum over rows and columns, then add each of those for the number of weights. Did you use “np.linalg.norm”? I’ve tried a few different ways and I’m still running into issues. Let me know if you find anything, and thanks for posting!

Hi pmVa,

This might just be a a nit in the implementation of your functions (eg. a misplaced parens or similar).
Are you using np.sum(np.square(Wl)) for each of W1, W2, W3?

What about if you decouple the sums from the multiplication by the constants?

Feel free to send me a DM with your code and I can take a look and maybe help.


Thank you so much! So I was using np.linalg.norm which gives the Frobenius Norm. That was not the correct way to go. Using your suggestion I corrected my code np.sum(np.square(Wl)). I should know better than to go against what is given by now. I’ve done this to myself before. Thank you again for all your help.!

Great to hear you found the issue.

I think it’s ok to experiment and see the differences between methods and ways to do something. The course just has a goal to show you a particular concept and it has to be rigid in that way. But after the assignments are done, you get to change things and experiment to see how results change based on that.

I guess in the next courses it’s more fun to test things out.


1 Like

Hi, @pmVA.

Just in case you were wondering what went wrong, you could compute the Frobenius norms of the weight matrices, but it probably wouldn’t make much sense since you’d have to square them to get rid of the square roots. The approach suggested by @neurogeek is much more straightforward.

Keep experimenting! :slight_smile:

1 Like

getting the same error!!!

Just an implementation error already fixed by @ans.

Good luck with the rest of the course :slight_smile: