fowlkes_mallows_score#
- sklearn.metrics.fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False)[原始碼]#
測量一組點的兩個叢集分群的相似度。
於 0.18 版本新增。
Fowlkes-Mallows 指數 (FMI) 定義為精確度和召回率的幾何平均值。
FMI = TP / sqrt((TP + FP) * (TP + FN))
其中
TP
是真陽性的數量(即在labels_true
和labels_pred
中都屬於同一叢集的點對數量),FP
是偽陽性的數量(即在labels_pred
中屬於同一叢集但在labels_true
中不屬於同一叢集的點對數量),而FN
是偽陰性的數量(即在labels_true
中屬於同一叢集但在labels_pred
中不屬於同一叢集的點對數量)。分數範圍從 0 到 1。高值表示兩個叢集之間具有良好的相似性。
在使用者指南中閱讀更多內容。
- 參數:
- labels_truearray-like,形狀為 (n_samples,),dtype=int
將資料分成不相交子集的叢集。
- labels_predarray-like,形狀為 (n_samples,),dtype=int
將資料分成不相交子集的叢集。
- sparsebool,預設為 False
使用稀疏矩陣在內部計算列聯表。
- 返回:
- scorefloat
產生的 Fowlkes-Mallows 分數。
參考文獻
範例
完美的標籤既是同質的又是完整的,因此得分為 1.0。
>>> from sklearn.metrics.cluster import fowlkes_mallows_score >>> fowlkes_mallows_score([0, 0, 1, 1], [0, 0, 1, 1]) np.float64(1.0) >>> fowlkes_mallows_score([0, 0, 1, 1], [1, 1, 0, 0]) np.float64(1.0)
如果類別成員完全分散在不同的叢集中,則分配是完全隨機的,因此 FMI 為空。
>>> fowlkes_mallows_score([0, 0, 0, 0], [0, 1, 2, 3]) 0.0