平衡準確度分數#
- sklearn.metrics.balanced_accuracy_score(y_true, y_pred, *, sample_weight=None, adjusted=False)[來源]#
計算平衡準確度。
在二元和多類別分類問題中,平衡準確度用於處理不平衡資料集。它被定義為每個類別所獲得的召回率的平均值。
當
adjusted=False
時,最佳值為 1,最差值為 0。請參閱 使用者指南 以了解更多資訊。
於 0.20 版本新增。
- 參數:
- y_true形狀為 (n_samples,) 的類陣列
真實(正確)目標值。
- y_pred形狀為 (n_samples,) 的類陣列
分類器傳回的估計目標。
- sample_weight形狀為 (n_samples,) 的類陣列,預設為 None
樣本權重。
- adjustedbool,預設為 False
如果為 true,則結果會針對機率進行調整,因此隨機效能會得分 0,同時保持完美效能得分為 1。
- 傳回值:
- balanced_accuracyfloat
平衡準確度分數。
另請參閱
average_precision_score
從預測分數計算平均精確度 (AP)。
precision_score
計算精確度分數。
recall_score
計算召回率分數。
roc_auc_score
從預測分數計算接收者操作特徵曲線下方面積 (ROC AUC)。
注意事項
有些文獻提倡平衡準確度的替代定義。我們的定義等同於使用類別平衡樣本權重的
accuracy_score
,並且與二元案例共享理想的屬性。請參閱使用者指南。參考文獻
[1]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 = [0, 1, 0, 0, 1, 0] >>> y_pred = [0, 1, 0, 0, 0, 1] >>> balanced_accuracy_score(y_true, y_pred) np.float64(0.625)