ValueError:查询数据维必须与训练数据维匹配
该如何解决该错误?
X_train2的形状为(4292,95),Y_train2的形状为(4292,)。 这是我写的代码:
11.4
这是错误代码,并返回以下消息:
X_train2 = X_train1.to_numpy()
y_train2 = y_train1.to_numpy()
fig, axes = plt.subplots(1, 3, figsize=(10,3))
for n_neighbors, ax in zip([1 ,3 ,9], axes):
knMod = KNeighborsClassifier(n_neighbors=n_neighbors)
knMod.fit(X_train1, y_train1)
mglearn.plots.plot_2d_separator(knMod, X_train2, fill=True, eps=0.5, ax=ax, alpha=.4)
mglearn.discrete_scatter(X_train2[:, 0], X_train2[:, 95], y_train2, ax=ax)
ax.set_title("{}KNN".format(n_neighbors))
ax.set_xlabel("feature 0")
ax.set_ylabel("feature 1")
axes[0].legend(loc=3)