rand_score#

sklearn.metrics.rand_score(labels_true, labels_pred)[源代码]#

兰德指数。

兰德指数通过考虑所有样本对并计数在预测和真实集群中相同或不同集群中分配的样本对来计算两个集群之间的相似性度量 [1] [2] .

原始RI评分 [3] 是:

RI = (number of agreeing pairs) / (number of pairs)

阅读更多的 User Guide .

参数:
labels_true形状类似阵列(n_samples,),dype =积分

用作参考的地面真相类标签。

labels_pred形状类似阵列(n_samples,),dype =积分

要评估的集群标签。

返回:
RI浮子

相似性得分在0.0和1.0之间(含),1.0代表完美匹配。

参见

adjusted_rand_score

调整后的兰德分数。

adjusted_mutual_info_score

调整后的相互信息。

引用

[2]

Wikipedia: Simple Matching Coefficient <https://en.wikipedia.org/wiki/Simple_matching_coefficient> _

[3]

Wikipedia: Rand Index <https://en.wikipedia.org/wiki/Rand_index> _

示例

完美匹配的标签评分为1偶数

>>> from sklearn.metrics.cluster import rand_score
>>> rand_score([0, 0, 1, 1], [1, 1, 0, 0])
1.0

将所有类成员分配到相同集群的标签是完整的,但可能并不总是纯粹的,因此会受到惩罚:

>>> rand_score([0, 0, 1, 2], [0, 0, 1, 1])
np.float64(0.83...)