【发布时间】:2016-08-27 18:11:42
【问题描述】:
我有一个数据集“x”和它的标签向量“y”。我想在应用 NaiveBayes 和交叉验证后绘制每个属性(对于“x”的每一列)的准确性。我想要一个条形图。 所以最后我需要有 3 条,因为“x”有 3 列。并且分类必须运行3次。每个特征有 3 种不同的精度。
每当我执行我的代码时,它都会显示:
ValueError:发现样本数量不一致的数组:[1 3]
弃用警告:将一维数组作为数据传递在 0.17 中已弃用,并将在 0.19 中引发 ValueError。如果您的数据具有单个特征,则使用 X.reshape(-1, 1) 重塑您的数据,如果它包含单个样本,则使用 X.reshape(1, -1)。
我做错了什么?
import matplotlib.pyplot as plt
import numpy as np
from sklearn import cross_validation
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
x = np.array([[0, 0.51, 0.00101], [3, 0.54, 0.00105], [6, 0.57, 0.00108], [9, 0.60, 0.00111], [1, 0.73, 0.00114], [5, 0.76, 0.00117], [8, 0.89, 120]])
y = np.array([1, 0, 0, 1, 1, 1, 0])
scores = list()
scores_std = list()
for i in range(x.shape[1]):
xA=x[:, i]
scoresKF2 = cross_validation.cross_val_score(clf, xA, y, cv=2)
scores.append(np.mean(scoresKF2))
scores_std.append(np.std(scoresKF2))
plt.bar(x[:,i], scores)
plt.show()
【问题讨论】:
标签: python-3.x matplotlib scikit-learn