Input data points are changed while plotting decision boundary

I am not sure if this can be asked here but I am finding for some help. I have finished the week3 assignment with planar data classification. After finishing the assignment I have tried building a neural network for my practice on a new dataset using sklearn's make_moons.

My code implementation is almost identical to that was done in assignment. This is how I created a new dataset.

X, y = datasets.make_moons(200, noise=0.30, random_state=8)
plt.scatter(X[:,0], X[:,1], c=y, cmap=plt.cm.Spectral)

image

After training the model and predicting, I used the plot_decision_boundary to look at how my models is separating the data points and to my surprise the data points are not the same as the input data points seen in above image. Below is the code.

def plot_decision_boundary(model, X, y):
    print(X.shape)
    print(y.shape)
    # Set min and max values and give it some padding
    x_min, x_max = X[0, :].min() - 1, X[0, :].max() + 1
    y_min, y_max = X[1, :].min() - 1, X[1, :].max() + 1
    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 grid
    Z = model(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[0,:], cmap=plt.cm.Spectral)

image

I am completely clueless how this is happening. Can someone kindly help me. For complete code that I have used, it can be seen here

Edit: The only change that I made is in below line where in original code c=y but here I have given c=y[0,:] because I was getting error as ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 200, 'y' with size 200. with c=y

plt.scatter(X[0, :], X[1, :], c=y[0,:], cmap=plt.cm.Spectral)

The only thing I can guess is that you are not using the same variables when you call plot_decision_boundary. Things like this don’t “just happen”: there must be a reason. So more careful examination of the code is required! :nerd_face: