Balanced Accuracy
MediumMachine LearningStatisticsArray
Description
Given an array of true binary labels and an array of predicted binary labels, return the balanced accuracy: the average of sensitivity (TP / (TP + FN)) and specificity (TN / (TN + FP)). Round the result to 4 decimal places.
Examples
Input:
[1,1,0,0], [1,0,1,0]Output:
0.5Explanation:
Averaging the true positive rate with the true negative rate gives each class equal weight, which corrects for imbalance.
Input:
[1,0], [1,0]Output:
1Explanation:
Averaging the true positive rate with the true negative rate gives each class equal weight, which corrects for imbalance.
Input:
[1,1,0,0], [1,1,0,0]Output:
1Explanation:
Averaging the true positive rate with the true negative rate gives each class equal weight, which corrects for imbalance.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
both classes appear