on-internet
← Community

IndexError: too many indices for array: array is 2-dimensional, but 3 were indexed

Stack Overflow ·

I have this code: import numpy as np import matplotlib.pyplot as plt import pandas as pd from sklearn.neighbors import KNeighborsClassifier knn = KNeighborsClassifier(n_neighbors = 3) knn.fit(X_train,Y_train) # Visualising the Test set results from matplotlib.colors import ListedColormap X_set, y_set = X_test, Y_test X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 1, stop = X_set[:, 0].max() + 1, step = 0.01),np.arange(start = X_set[:, 1].min() - 1, stop = X_set[:, 1].max() + 1, step = 0.01)) plt.sactter(X1, X2, knn.predict(np.array([X1.ravel(),X2.ravel()]).T).reshape(X1.shape), alp

Comments

Sign in or sign up to comment and upvote.

No comments yet.