-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValidator.py
51 lines (39 loc) · 1.49 KB
/
Validator.py
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
45
46
47
48
49
50
51
# Author Alvaro Esperanca
class Validator(object):
def __init__(self):
self.tp = 0.0
self.tn = 0.0
self.fp = 0.0
self.fn = 0.0
def validate(self, validationLabels, testLabels):
for i in range(len(validationLabels)):
if validationLabels[i] == 1.0 and testLabels[i] == 1.0:
self.tp += 1
if validationLabels[i] == 1.0 and testLabels[i] == -1.0:
self.fn += 1
if validationLabels[i] == -1.0 and testLabels[i] == -1.0:
self.tn += 1
if validationLabels[i] == -1.0 and testLabels[i] == 1.0:
self.fp += 1
def truePositives(self):
return self.tp
def trueNegatives(self):
return self.tn
def falsePositives(self):
return self.fp
def falseNegatives(self):
return self.fn
def precision(self):
return self.tp / (self.tp + self.fp)
def recall(self):
return self.tp / (self.tp + self.fn)
def accuracy(self):
return (self.tp + self.tn) / (self.tp + self.tn + self.fp + self.fn)
def report(self):
print ("%-20s %-5d" % ("True Positives:", self.tp) )
print ("%-20s %-5d" % ("True Negatives:", self.tn) )
print ("%-20s %-5d" % ("False Positives:", self.fp) )
print ("%-20s %-5d" % ("False Negatives:", self.fn) )
print ("\n")
print ("%-20s %.2f" % ("Accuracy:", self.precision()) )
print ("%-20s %.2f" % ("Recall:", self.recall()) )