【发布时间】:2021-07-11 21:01:16
【问题描述】:
我试图在X_test 数据上绘制meshgrid,但是当我运行代码时出现以下异常:
ValueError:连接轴的所有输入数组维度必须完全匹配,但沿维度 0,索引 0 处的数组大小为 196548,索引 1 处的数组大小为 14550
变量xx 与所有问题有关,但我看不到解决问题的方法。
classifier = BaggingClassifier(base_estimator = KNeighborsClassifier(),
max_samples = 10,
n_estimators = 100)
X0, X1 = X_test.iloc[:,0], X_test.iloc[:, 1]
xx, yy = make_meshgrid(X0, X1)
def make_meshgrid(x, y, h=0.02):
x_min, x_max = x.min() - 1, x.max() + 1
y_min, y_max = y.min() - 1, y.max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h), sparse=True)
return xx, yy
def plot_contours(ax, clf, xx, yy, **params):
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
out = ax.contourf(xx, yy, Z, **params)
return out
# Pass the data. make_meshgrid will automatically identify the min and max points to draw the grid
plot_contours(plt, classifier, xx, yy,
cmap=plt.cm.coolwarm,
alpha=0.8)
# plot the meshgrid
plt.scatter(X0, X1, cmap=plt.cm.coolwarm,s=20, edgecolors='k', alpha=0.2)
【问题讨论】:
-
具体在哪里?请使用完整的错误跟踪更新您的问题。此外,问题与
deep-learning无关 - 请不要向无关标签发送垃圾邮件(已删除)。
标签: python matplotlib scikit-learn