I have a multi-class classification task. I can obtain accuracy and balanced accuracy metrics from sklearn in Python but they both spew one figure. How can I obtain balanced accuracy for every class as well? Note that, when I use the caret package in R for modelling, with the metrics report I get balanced accuracy for every class (e.g., the last row in the below example), and I'd like to have the same functionality in sklearn or any accompanying Python library if possible.
Example in caret metrics in R
confusionMatrix(testSet$classes,testSet$pred_model)
output:
Class: A Class: B Class: C Class: D Class: E Class: F
Sensitivity 0.37143 0.23404 0.25490 0.15254 0.30909 0.27692
Specificity 0.85921 0.84528 0.85057 0.83004 0.86381 0.86235
Pos Pred Value 0.25000 0.21154 0.25000 0.17308 0.32692 0.34615
Neg Pred Value 0.91538 0.86154 0.85385 0.80769 0.85385 0.81923
Prevalence 0.11218 0.15064 0.16346 0.18910 0.17628 0.20833
Detection Rate 0.04167 0.03526 0.04167 0.02885 0.05449 0.05769
Detection Prevalence 0.16667 0.16667 0.16667 0.16667 0.16667 0.16667
Balanced Accuracy 0.61532 0.53966 0.55274 0.49129 0.58645 0.56964
Example in sklearn in Python
acc=accuracy_score(y_test,y_pred)
0.52345
bal_acc=balanced_accuracy_score(y_test,y_pred)
0.53657
Thanks!