同質性分數#

sklearn.metrics.homogeneity_score(labels_true, labels_pred)[來源]#

根據真實標籤,計算群集標籤的同質性度量。

如果一個群集的所有資料點都只屬於單一類別的成員,則此群集結果符合同質性。

此度量與標籤的絕對值無關:類別或群集標籤值的排列不會以任何方式改變分數值。

此度量不對稱:將 label_truelabel_pred 交換將返回 completeness_score,這在一般情況下會有所不同。

使用者指南 中閱讀更多內容。

參數:
labels_truearray-like of shape (n_samples,)

作為參考的真實類別標籤。

labels_predarray-like of shape (n_samples,)

要評估的群集標籤。

返回:
homogeneityfloat

分數介於 0.0 和 1.0 之間。1.0 表示完美的同質性標籤。

另請參閱

completeness_score

群集標籤的完整性度量。

v_measure_score

V 度量(使用算術平均選項的 NMI)。

參考文獻

範例

完美的標籤具有同質性

>>> from sklearn.metrics.cluster import homogeneity_score
>>> homogeneity_score([0, 0, 1, 1], [1, 1, 0, 0])
np.float64(1.0)

將類別進一步劃分為更多群集的不完美標籤可以具有完美的同質性

>>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 0, 1, 2]))
1.000000
>>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 1, 2, 3]))
1.000000

包含來自不同類別的樣本的群集不會產生同質的標籤

>>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 1, 0, 1]))
0.0...
>>> print("%.6f" % homogeneity_score([0, 0, 1, 1], [0, 0, 0, 0]))
0.0...