fowlkes_mallows_score#
- sklearn.metrics.fowlkes_mallows_score(labels_true, labels_pred)[source]#
衡量一组点的两个聚类的相似性。
版本 0.18 新增。
Fowlkes-Mallows 指数 (FMI) 定义为精确率和召回率的几何平均值。
FMI = TP / sqrt((TP + FP) * (TP + FN))
其中
TP是真阳性 (True Positive) 的数量(即在labels_true和labels_pred中属于同一簇的点对数量),FP是假阳性 (False Positive) 的数量(即在labels_pred中属于同一簇但在labels_true中不属于同一簇的点对数量),而FN是假阴性 (False Negative) 的数量(即在labels_true中属于同一簇但在labels_pred中不属于同一簇的点对数量)。得分范围从 0 到 1。高值表示两个聚类之间具有良好的相似性。
阅读更多内容请参考 用户指南。
- 参数:
- labels_true形状为 (n_samples,) 的类数组
将数据聚类为不相交的子集。
- labels_pred形状为 (n_samples,) 的类数组
将数据聚类为不相交的子集。
- 返回:
- scorefloat
所得的 Fowlkes-Mallows 得分。
References
示例
完美的标签既是同质的又是完整的,因此分数为 1.0
>>> from sklearn.metrics.cluster import fowlkes_mallows_score >>> fowlkes_mallows_score([0, 0, 1, 1], [0, 0, 1, 1]) 1.0 >>> fowlkes_mallows_score([0, 0, 1, 1], [1, 1, 0, 0]) 1.0
如果类成员被完全拆分到不同的簇中,则分配是完全随机的,因此 FMI 为零。
>>> fowlkes_mallows_score([0, 0, 0, 0], [0, 1, 2, 3]) 0.0