sklearn.metrics.balanced_accuracy_score?

sklearn.metrics.balanced_accuracy_score(y_true, y_pred, *, sample_weight=None, adjusted=False)

[源碼]

計算平衡精度

二元和多類分類問題中的平衡精度可以處理不平衡的數據集。 它定義為每個類獲得的召回率的平均值。

adjusted=False時,最佳值為1,最差值為0。

用戶指南中閱讀更多內容。

0.20版中的新功能。

參數 說明
y_true 1d array-like
真實的目標值。
y_pred 1d array-like
分類器返回的估計目標。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。
adjusted bool, default=False
如果為true,將根據偶然性對結果進行調整,以便隨機性能得分為0,而完美性能得分為1。
返回值 說明
balanced_accuracy float

另見

recall_score, roc_auc_score

一些文獻提出了平衡精度的替代定義。我們的定義等效于具有類平衡的樣本權重的accuracy_score,并與二進制情況共享理想的屬性。 請參閱用戶指南

參考

Brodersen, K.H.; Ong, C.S.; Stephan, K.E.; Buhmann, J.M. (2010). The balanced accuracy and its posterior distribution. Proceedings of the 20th International Conference on Pattern Recognition, 3121-24.

2

John. D. Kelleher, Brian Mac Namee, Aoife D’Arcy, (2015). Fundamentals of Machine Learning for Predictive Data Analytics: Algorithms, Worked Examples, and Case Studies.

示例

>>> from sklearn.metrics import balanced_accuracy_score
>>> y_true = [010010]
>>> y_pred = [010001]
>>> balanced_accuracy_score(y_true, y_pred)
0.625