-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcConfusionMatrix.py
More file actions
38 lines (30 loc) · 1.36 KB
/
calcConfusionMatrix.py
File metadata and controls
38 lines (30 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def calcConfusionMatrixBinary():
# Calculate confusion matrix for binary classification
tP = float(input("Enter value of True Positive: "))
fP = float(input("Enter value of False Positive: "))
tN = float(input("Enter value of True Negative: "))
fN = float(input("Enter value of False Negative: "))
precision = tP / (tP + fP)
recall = tP / (tP + fN)
f1 = 2 * (precision * recall) / (precision + recall)
print("Precision score is - " + str(precision * 100) + "%")
print("Recall score is - " + str(recall * 100) + "%")
print("F1 score is - " + str(f1 * 100) + "%")
# Prepare confusion matrix
confusion_matrix = [[tN, fP], [fN, tP]]
return confusion_matrix
def calcConfusionMatrixMulti():
# Calculate confusion matrix for multi-class classification
# You can modify this part to accept input for multi-class confusion matrix
pass
classifierType = input("Is this a binary type classification?(Y/N) - ")
if classifierType == "Y":
confusion_matrix = calcConfusionMatrixBinary()
else:
confusion_matrix = calcConfusionMatrixMulti()
print("Confusion Matrix is:")
for row in confusion_matrix:
print(row)
# Display confusion matrix in HTML
print('<script>document.getElementById("output").style.display = "block";</script>')
print('<script>updateConfusionMatrix(' + str(confusion_matrix) + ');</script>')