平衡准确率评分#
- sklearn.metrics.balanced_accuracy_score(y_true, y_pred, *, sample_weight=None, adjusted=False)[source]#
- 计算平衡准确率。 - 平衡准确率用于处理不平衡数据集的二元和多分类问题。它定义为在每个类别上获得的召回率的平均值。 - 当 - adjusted=False时,最佳值为1,最差值为0。- 更多信息请阅读用户指南。 - 在0.20版本中添加。 - 参数:
- y_truearray-like of shape (n_samples,)
- 真实目标值。 
- y_predarray-like of shape (n_samples,)
- 分类器预测的目标值。 
- sample_weightarray-like,形状 (n_samples,),默认为 None
- 样本权重。 
- adjusted布尔值,默认为 False
- 如果为 True,则结果将针对偶然性进行调整,使随机性能的分数为 0,同时保持完美性能的分数为 1。 
 
- 返回:
- balanced_accuracy浮点数
- 平衡准确率得分。 
 
 - 另请参阅 - average_precision_score
- 根据预测分数计算平均精度 (AP)。 
- 精确率评分
- 计算精确率得分。 
- 召回率评分
- 计算召回率得分。 
- ROC曲线下面积 (AUC)
- 根据预测分数计算受试者工作特征曲线下面积 (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) 
