I built multiclass classification model (with 5 classes in target) in Python and I have confusion matrix like below:
confusion_matrix(y_test, model.predict(X_test))
[[2006 114 80 312 257]
[567 197 87 102 155]
[256 84 316 39 380]
[565 30 67 592 546]
[363 71 186 301 1402]]
How can I calculate based on confusion matrix above, the following values:
- True Negative
- False Positive
- False Negative
- True Positive
- Accuracy
- True Positive Rate
- False Positive Rate
- True Negative Rate
- False Negative Rate
I have the following function to calculate that for binnary target, but how can I modify that function to calculate that for my 5 classes target ?
def xx(model, X_test, y_test):
CM = confusion_matrix(y_test, model.predict(X_test))
print(CM)
print("-"*40)
TN = CM[0][0]
FP = CM[0][1]
FN = CM[1][0]
TP = CM[1][1]
sensitivity=TP/float(TP+FN)
specificity=TN/float(TN+FP)
print("True Negative:", TN)
print("False Positive:", FP)
print("False Negative:", FN)
print("True Positive:", TP)
print("Accuracy", round((TN + TP) / len(model.predict(X_test)) * 100, 2), "%")
print("True Positive rate",round(TP/(TP+FN)*100,2), "%")
print("False Positive rate",round(FP/(FP+TN)*100,2), "%")
print("True Negative rate",round(TN/(FP+TN)*100,2), "%")
print("False Negative rate",round(FN/(FN+TP)*100,2), "%")