4 - Two-layer Neural Network

Hello,
I got the following error on 4 - Two-layer Neural Network excercise:
Appreciate your help

Cost after iteration 1: 0.6911515437466783
Cost after first iteration: 0.693049735659989
Cost after iteration 1: 0.6868374843350817
Error: Datatype mismatch. in variable 0. Got type: <class 'numpy.float64'>  but expected type <class 'numpy.ndarray'>
Cost after iteration 1: 0.6868374843350817
Cost after iteration 1: 0.6868374843350817
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
Cost after iteration 2: 0.5470404797767533
Error: Wrong output for variable W1.
Error: Wrong output for variable b1.
Error: Wrong output for variable W2.
Error: Wrong output for variable b2.
 1  Tests passed
 3  Tests failed
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-70-f9ec5304d38d> in <module>
      3 print("Cost after first iteration: " + str(costs[0]))
      4 
----> 5 two_layer_model_test(two_layer_model)

~/work/release/W4A2/public_tests.py in two_layer_model_test(target)
     75     ]
     76 
---> 77     multiple_test(test_cases, target)
     78 
     79 

~/work/release/W4A2/test_utils.py in multiple_test(test_cases, target)
    140         print('\033[92m', success," Tests passed")
    141         print('\033[91m', len(test_cases) - success, " Tests failed")
--> 142         raise AssertionError("Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.".format(target.__name__))
    143 

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

Hello @Manuel_Trujillo,

The key is here that your function does not return variables of the expected type. Note that you are returning two variables: parameters and costs. parameters should be a dict of four entries:W1, W2, b1, and b2. Each of them should be of type numpy.ndarray since they are all arrays. However, it appears that it is getting a scalar (of type numpy.float64) instead.

There are two places where parameters are modified:

    # Initialize parameters dictionary, by calling one of the functions you'd previously implemented
    #(≈ 1 line of code)
    # parameters = ...

and

        # Update parameters.
        #(approx. 1 line of code)
        # parameters = ...

Those are the places you need to pay attention to. One way is to keep track of how the type of parameters['W1'] has changed over the course of the program by printing its type. You can do so by adding print(type(parameters['W1'])) after each of the above two modifications.

If W1 is all fine, but you are still getting the same Data mismatch error, then look into W2, b1 and b2 instead.

As soon as you find that the type is not a numpy.ndarray, you have spoted it. Then you need to read the instructions again and think about how to make the correction.

After you have passed those tests, remember to remove the added print lines as they will interfere with the autograder at submission and fail it.

Cheers,
Raymond

1 Like

Thanks Raymond for the detailed explanation!

Thanks,

Manny

No problem @Manuel_Trujillo

Raymond