sklearn.metrics.homogeneity_score?
sklearn.metrics.homogeneity_score(labels_true, labels_pred)
給定真實值的聚類標簽的同質性度量。
如果聚類結果的所有聚類僅包含屬于單個類的成員的數據點,則聚類結果滿足同質性。
此指標獨立于標簽的絕對值:類別或簇標簽值的排列不會以任何方式改變得分值。
此度量不是對稱的:將label_true與label_pred切換將返回completeness_score
,該分數通常會有所不同。
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
labels_true | int array, shape = [n_samples] 真實類標簽用作參考 |
labels_pred | array-like of shape (n_samples,) 聚類標簽以進行評估 |
返回值 | 說明 |
---|---|
homogeneity | float 分數介于0.0和1.0之間。 1.0代表完全的均質貼標 |
另見:
參考
示例
完全標簽是同質的:
>>> from sklearn.metrics.cluster import homogeneity_score
>>> homogeneity_score([0, 0, 1, 1], [1, 1, 0, 0])
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...