Week 1 - L2 Regurlarization - Exercise 1

My code is failing the second test. I already checked the equations, they seem right.

    LW = np.sum(np.square(W1)) + np.sum(np.square(W2)) + np.sum(np.square(W3))
    
    L2_regularization_cost =  LW * (lambd/2*m)
  

Error:

AssertionError                            Traceback (most recent call last)
<ipython-input-57-8a6336484845> in <module>
      3 print("cost = " + str(cost))
      4 
----> 5 compute_cost_with_regularization_test(compute_cost_with_regularization)

~/work/release/W1A2/public_tests.py in compute_cost_with_regularization_test(target)
     30     ]
     31 
---> 32     single_test(test_cases, target)
     33 
     34 def backward_propagation_with_regularization_test(target):

/opt/conda/lib/python3.7/site-packages/dlai_tools/testing_utils.py in single_test(test_cases, target)
    129         print('\033[91m', len(test_cases) - success, " Tests failed")
    130         raise AssertionError(
--> 131             "Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.".format(target.__name__))
    132 
    133 

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

That looks like a classic “order of operations” problem. Try running the following code and watch what happens:

m = 5.
x = 1. / 2. * m
y = 1. / (2. * m)

If you’re expecting that x and y end up with the same value, you’re in for a surprise!