Week 3 Assignment: Test the Model on the Planar Dataset

I am running this code

Build a model with a n_h-dimensional hidden layer

parameters = nn_model(X, Y, n_h = 4, num_iterations = 10000, print_cost=True)

Plot the decision boundary

plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y)
plt.title("Decision Boundary for hidden layer size " + str(4))

and the error message is:

Cost after iteration 0: 0.693048
Cost after iteration 1000: 0.288083
Cost after iteration 2000: 0.254385
Cost after iteration 3000: 0.233864
Cost after iteration 4000: 0.226792
Cost after iteration 5000: 0.222644
Cost after iteration 6000: 0.219731
Cost after iteration 7000: 0.217504
Cost after iteration 8000: 0.219430
Cost after iteration 9000: 0.218551

ValueError Traceback (most recent call last)
4 # Plot the decision boundary
----> 5 plot_decision_boundary(lambda X: predict(parameters, X.T), X, Y)
6 plt.title("Decision Boundary for hidden layer size " + str(4))

~/work/release/W3A1/planar_utils.py in plot_decision_boundary(model, X, y)
14 # Predict the function value for the whole grid
15 Z = model(np.c_[xx.ravel(), yy.ravel()])
ā€”> 16 Z = Z.reshape(xx.shape)
17 # Plot the contour and training examples
18 plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)

ValueError: cannot reshape array of size 3 into shape (1008,1030)

You must be referencing global variables instead of the parameters that were passed in someplace. Check your nn_model function first. Did that pass the internal tests in the notebook?

1 Like

Yes there was a problem due to some global variable. Thanks

Great! Iā€™m glad to hear that you figured it out. I was just going over my code to try to understand where your problem might be, but I had not figured it out yet. This is actually a fairly common occurrence. Would you mind sharing where the problem was, so that it might help other students later? Thanks!