Python准确性检查给出0翻转分类结果
我正在使用Python准确性检查给出0翻转分类结果,python,scikit-learn,classification,Python,Scikit Learn,Classification,我正在使用sklearn.metrics 我的分类测试数据标签用于 [1 1 0 0 0 1 1] Kmeans给出了如下标签: [0 0 1 1 1 0 0] 基本上,Kmeans分类正确,但标签翻转了精度检查的精度为0% 我的代码 X_full, y_full = make_blobs(n_samples=nsamples, centers=2, n_features=no_f
sklearn.metrics
我的分类测试数据标签用于
[1 1 0 0 0 1 1]
Kmeans给出了如下标签:
[0 0 1 1 1 0 0]
基本上,Kmeans分类正确,但标签翻转了<代码>精度检查的精度为0%
我的代码
X_full, y_full = make_blobs(n_samples=nsamples,
centers=2,
n_features=no_feat,
random_state=ran)
X, X_test, y, y_test = train_test_split(X_full, y_full, test_size=0.2)
kmeans = KMeans(2, random_state=3)
labels = kmeans.fit(X).predict(X_test)
acc = accuracy_score(y_test, labels)
print("KMeans:", acc)
关于如何实现这一点有什么想法吗
编辑:我也不能简单地翻转标签,因为有时它确实能正确分类。在其他情况下,我也有多个标签
谢谢你除了准确度评分,你能试一下吗 例如,您可以尝试
v\u measure\u score
而不是accurity\u score
据
此度量与标签的绝对值无关:a
类或簇标签值的排列不会更改
以任何方式为价值打分
为了衡量集群检索类的效果,如果您恰好有标签,那么出于您指出的原因,使用
accurity\u score
是错误的。本质上,这是因为集群算法为其集群提供任意标签。相反,在这种情况下,您应该使用调整后的兰德分数,无论标签如何,它都将返回相同的分数:
from sklearn.metrics.cluster import adjusted_rand_score
print(adjusted_rand_score([0, 0, 1, 1], [0, 0, 1, 1]))
print(adjusted_rand_score([0, 0, 1, 1], [1, 1, 0, 0]))
两者都应该返回1.0