-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
44 lines (35 loc) · 1.01 KB
/
Copy pathmain.py
File metadata and controls
44 lines (35 loc) · 1.01 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
39
40
41
42
43
44
import pandas as pd
import numpy as np
from sklearn.metrics import *
cm = confusion_matrix(self.y_test, self.y_pred)
get_tp_from_cm(cm)
get_tn_from_cm(cm)
get_fp_from_cm(cm)
get_fn_from_cm(cm)
# True positives are the diagonal elements
def get_tp_from_cm(self, cm):
tp = np.diag(cm)
print('tp', np.sum(np.diag(cm)))
return np.sum(tp)
def get_tn_from_cm(self, cm):
tn = []
for i in range(self.n_classes):
temp = np.delete(cm, i, 0) # delete ith row
temp = np.delete(temp, i, 1) # delete ith column
tn.append(sum(sum(temp)))
print('tn ', np.sum(tn))
return np.sum(tn)
# Sum of columns minus diagonal
def get_fp_from_cm(self, cm):
fp = []
for i in range(self.n_classes):
fp.append(sum(cm[:, i]) - cm[i, i])
print('fp ', np.sum(fp))
return np.sum(fp)
# Sum of rows minus diagonal
def get_fn_from_cm(self, cm):
fn = []
for i in range(self.n_classes):
fn.append(sum(cm[i, :]) - cm[i, i])
print('fn', np.sum(fn))
return np.sum(fn)