# Course 2, Week 2 Regularization Programming Exercise

Hi there,

I am doing the Week 2, Regularization, coding exercise in the second course of DLS, and I am passing all of the cells which I have to code in, but when running the final cells:

parameters = model(train_X, train_Y, keep_prob = 0.86, learning_rate = 0.3)

print ("On the train set:")
predictions_train = predict(train_X, train_Y, parameters)
print ("On the test set:")
predictions_test = predict(test_X, test_Y, parameters)

I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-148-9bfabb849b4f> in <module>
----> 1 parameters = model(train_X, train_Y, keep_prob = 0.86, learning_rate = 0.3)
2
3 print ("On the train set:")
4 predictions_train = predict(train_X, train_Y, parameters)
5 print ("On the test set:")

<ipython-input-110-0f6a391419fd> in model(X, Y, learning_rate, num_iterations, print_cost, lambd, keep_prob)
32             a3, cache = forward_propagation(X, parameters)
33         elif keep_prob < 1:
---> 34             a3, cache = forward_propagation_with_dropout(X, parameters, keep_prob)
35
36         # Cost function

<ipython-input-144-317bef803daa> in forward_propagation_with_dropout(X, parameters, keep_prob)
42     D1 = (D1 < keep_prob).astype(int)
43
---> 44     A1 = A1 * D1
45     A1 = A1 * (1 / keep_prob)
46     # YOUR CODE ENDS HERE

ValueError: operands could not be broadcast together with shapes (20,211) (2,5)

I donâ€™t really understand why this is happening since all the previous tests come back saying â€śAll tests passedâ€ť.

Any help would be greatly appreciated.

Thanks,

Michael

It looks like maybe you are referencing global variables from the test case when you initialize D1, but it doesnâ€™t work when you use the code in the general case.

1 Like