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形状为 (n_samples,) 的 array-like
真实(正确)的目标值。
- y_pred形状为 (n_samples,) 的类数组
分类器返回的估计目标。
- sample_weightshape 为 (n_samples,) 的 array-like, default=None
样本权重。
- adjustedbool, 默认=False
当为 True 时,结果会根据机会进行调整,以便随机性能得分为 0,同时保持完美性能得分为 1。
- 返回:
- balanced_accuracyfloat
平衡准确度分数。
另请参阅
average_precision_score从预测分数计算平均精度 (AP)。
precision_score计算精度分数。
recall_score计算召回率分数。
roc_auc_score从预测分数计算接收者操作特征曲线下面积 (ROC AUC)。
注意事项
一些文献提倡平衡准确度的替代定义。我们的定义等同于使用类别平衡样本权重的
accuracy_score,并与二分类情况共享理想的属性。请参阅用户指南。References
[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) 0.625