-
Notifications
You must be signed in to change notification settings - Fork 221
NameError: name 'pred_func' is not defined #5
Description
@JannesKlaas
Hi Jannes,
In chapater 1,
...
A deeper network
...
Helper function to plot a decision boundary.
If you don't fully understand this function don't worry, it just generates the contour plot below.
def plot_decision_boundary(pred_func):
# Set min and max values and give it some padding
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
h = 0.01
# Generate a grid of points with distance h between them
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
# Predict the function value for the whole gid
Z = pred_func(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
# Plot the contour and training examples
plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
plt.scatter(X[:, 0], X[:, 1], c=y.flatten(), cmap=plt.cm.Spectral)
NameError Traceback (most recent call last)
/tmp/ipykernel_27/694468409.py in
15
16 #Plot the decision boundary
---> 17 plot_decision_boundary(lambda x: predict(model, x))
18 plt.title("Decision Boundary for hidden layer size 3")
19
/tmp/ipykernel_27/2764471563.py in plot_decision_boundary(pre_func)
114 xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
115 #Predict the function value for the whole gid
--> 116 Z = pred_func(np.c_[xx_ravel(), yy_ravel()])
117 Z = Z.reshape(xx.shape)
118 #Plot the contour and training examples
NameError: name 'pred_func' is not defined