I'm working on multi-class classification in python (4 classes). To obtain the results of each class separately, I used the following code:
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
cnf_matrix = cm
FP = cnf_matrix.sum(axis=0) - np.diag(cnf_matrix)
FN = cnf_matrix.sum(axis=1) - np.diag(cnf_matrix)
TP = np.diag(cnf_matrix)
TN = cnf_matrix.sum() - (FP + FN + TP)
FP = FP.astype(float)
FN = FN.astype(float)
TP = TP.astype(float)
TN = TN.astype(float)
# Sensitivity, hit rate, recall, or true positive rate
TPR = TP/(TP+FN)
print('TPR : ',TPR)
# Specificity or true negative rate
TNR = TN/(TN+FP)
print('TNR : ',TNR)
# Precision or positive predictive value
PPV = TP/(TP+FP)
print('PPV : ',PPV)
# Fall out or false positive rate
FPR = FP/(FP+TN)
print('FPR : ',FPR)
# False negative rate
FNR = FN/(TP+FN)
print('FNR : ',FNR)
# Overall accuracy
ACC = (TP+TN)/(TP+FP+FN+TN)
print('ACC : ',ACC)
I obtained the following results:
TPR : [0.98398792 0.99999366 0.99905393 0.99999548]
TNR : [0.99999211 0.99997989 1. 0.99773928]
PPV : [0.99988488 0.99996832 1. 0.99810887]
FPR : [7.89469529e-06 2.01061605e-05 0.00000000e+00 2.26072224e-03]
FNR : [1.60120846e-02 6.33705530e-06 9.46073794e-04 4.52196090e-06]
ACC : [0.99894952 0.99998524 0.99999754 0.99896674]
Now, I want to calculate the average value of each metrics ?! Should I just add the four values to each others, after that divide the results on 4 ? for example, for the accuracy (ACC) : (0.99894952 + 0.99998524 + 0.99999754 + 0.99896674)/4 ?!! Or What should I do exactly ? Help please.