Bug in 5.2 - Test the Model on the Planar Dataset

Hi,

I’m on the programming assignment in week 3, specifically at 5.2 - Test the Model on the Planar Dataset

Everything so far works and I have passed all the tests.
However when I run the cell(no solution here, we just have to run the cell)

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))

I get this output with the error. It looks like a error coming out of the grader, and not through student code:
Cost after iteration 0: 0.693162
Cost after iteration 1000: 0.258625
Cost after iteration 2000: 0.239334
Cost after iteration 3000: 0.230802
Cost after iteration 4000: 0.225528
Cost after iteration 5000: 0.221845
Cost after iteration 6000: 0.219094
Cost after iteration 7000: 0.220661
Cost after iteration 8000: 0.219409
Cost after iteration 9000: 0.218485

AttributeError Traceback (most recent call last)
in
3
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)

AttributeError: ‘list’ object has no attribute ‘reshape’

Let me know if anyone else faced a similar problem, or any fixed, or if I’m going wrong somewhere

Thanks!

The grader is only used when you “submit” a notebook for grading.

The tests that are built into the notebook are not “the grader”. They’re just
test cases to help you debug your code.

If a cell that runs a test throws some asserts or errors, it is due to bugs in your code which is being tested.

In this case, the error message points to where your predict() function is being used to plot the decision boundary.

1 Like

Yes, as Tom says, just because you didn’t write that specific test cell doesn’t mean that the problem doesn’t result from bugs in your code. Note that it calls the predict function that you wrote. Where does the variable Z come from in that line that “throws”? It has the wrong type: a list instead of a numpy array.

@paulinpaloalto

model = keras.Sequential(
    [
        layers.Dense(2, activation="relu", name="layer1"),
        layers.Dense(3, activation="relu", name="layer2"),
        layers.Dense(4, name="layer3"),
    ]
)
# Call model on a test input
x = ops.ones((3, 3))
y = model(x)

What does the last line do?

y=model(x)

Can anyone please list down the commands it runs in sequence? like model.compile, model.fit, model.predict etc. in correct order.

Can you please help me with this?

This post is a duplicate, please don’t post the same question in multiple topics.