【问题标题】:Applying RAND index with cluster numbers and cluster labels应用带有簇号和簇标签的 RAND 索引
【发布时间】:2022-01-03 14:23:18
【问题描述】:

我有一组评论,我用 k-means 对它们进行了聚类,并得到了每条评论所属的集群(例如:1,2,3...)。我还有这些属于哪些集群的真实标签,例如:位置、食物等),我需要将它们与兰德指数进行比较。

由于我有集群编号和集群标签,我如何应用 Rand 索引进行比较?

我应该遵循任何中间步骤吗?

编辑: 我看过Rand Index function (clustering performance evaluation) 的帖子,但它没有回答我的问题。

在那个问题中,你有

labels_true = [1, 1, 0, 0, 0, 0]
labels_pred = [0, 0, 0, 1, 0, 1]

但我所拥有的是如下所示,

labels_true = ['food', 'view', 'room', 'food', 'staff', 'staff']
labels_pred = [0, 0, 0, 1, 0, 1]

非常感谢任何帮助。

【问题讨论】:

标签: python performance nlp cluster-analysis k-means


【解决方案1】:

只需使用sklearn.metrics.rand_score 函数:

from sklearn.metrics import rand_score

rand_score(labels_true, labels_pred)

真实标签和预测标签是否在不同域中具有值并不重要。请看示例:

>>> rand_score(['a', 'b', 'c'], [5, 6, 7])
1.0
>>> rand_score([0, 1, 2], [5, 6, 7])
1.0
>>> rand_score(['a', 'a', 'b'], [0, 1, 2])
0.6666666666666666
>>> rand_score(['a', 'a', 'b'], [7, 7, 2])
1.0

【讨论】:

  • 当真实值和预测值在不同的域时,似乎无法应用 Jaccard 相似度。 @Riccardo Bucco 你知道如何处理这种情况吗?
  • @lse23 请打开另一个问题 :)
猜你喜欢
  • 1970-01-01
  • 2022-11-05
  • 1970-01-01
  • 1970-01-01
  • 2017-04-04
  • 1970-01-01
  • 2013-05-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多