gpt4 book ai didi

python - "ValueError: query data dimension must match training data dimension"

转载 作者:行者123 更新时间:2023-11-30 09:40:35 33 4
gpt4 key购买 nike

如何在 3 列 X_train 数据上使用以下代码。错误

"ValueError: query data dimension must match training data dimension"

在执行以下代码时发现具有 3 列 X_train 数据。

# Visualising the Training set results
from matplotlib.colors import ListedColormap
X_set, y_set = X_train, y_train
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.contourf(X1, X2, classifier.predict(np.array([X1.ravel(), X2.ravel()]).T).reshape(X1.shape),
alpha = 0.75, cmap = ListedColormap(('red', 'green')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1],
c = ListedColormap(('red', 'green'))(i), label = j)
plt.title('K-NN (Training set)')
plt.xlabel('Age')
plt.ylabel('Estimated Salary')
plt.legend()
plt.show()

最佳答案

在训练和预测期间,特征向量的维数必须相同。如果您想使用 3 列进行预测,则模型还必须使用 3 列进行训练。

关于python - "ValueError: query data dimension must match training data dimension",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58936237/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com