由于聚类的自动索引与真实标签不匹配,如何评估 K-Means 聚类?

How to evaluate K-Means Clustering since automatic indexes of clusters don't match true labels?

由于聚类的自动索引可能是原始标签的排列,我们如何衡量 K-Means 聚类算法(例如,生成混淆矩阵)的准确性?

k-means是clustering(分组算法,不用于分类),因此无法检验和分析准确率。 k-means 的主要概念是找到一个 data-points 的集群,它最大化“between-cluster” 距离(并且没有标签的概念,因此,你无法获得精度矩阵).更多见解:https://scikit-learn.org/stable/modules/clustering.html#k-means

必须使用 sklearn.cluster.KMeans 中的 predict 方法手动分析准确性(假设您想要可视化哪个聚类由哪些数据点组成)。它基本上是“预测 X 中每个样本所属的最近集群”。 (from documentation)

我也不完全明白你的意思。您的原始标签可能是真实标签。 k-means 提供的聚类结果通常是一个整数,其范围与您希望 k-means 算法给您的 k 个聚类一样多。

我通常使用 pandas.crosstab 函数来可视化带有 kmeans 标记的 groundtruth 标记的定位 cross-tabulation。

为了更好的可视化,您可能需要使用以下内容:

import seaborn as sns
import matplotlib.pyplot as plt

plt.figure(figsize=(30,10))

# plot the heatmap for correlation matrix
ax = sns.heatmap(crosstab_groundtruth_kmeans.T, 
                square=True, annot=True, fmt='.2f')

ax.set_yticklabels(
    ax.get_yticklabels(),
    rotation=0);

out:

祝你好运!~