-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.py
33 lines (28 loc) · 980 Bytes
/
validation.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
class validator(object):
def __init__(self, data, label, shape):
self.accuracy = []
self.candidate_result = 0
self.data = data
self.label = label
self.weight_shape = shape
def validate(self, weight):
old = weight.shape
weight.shape = self.weight_shape
predict = (weight.dot(self.data)).argmax(0)
accuracy = (predict == self.label.flatten())
res = accuracy.mean()
weight.shape = old
if len(self.accuracy) == 0:
self.accuracy.append(res)
elif res >= self.accuracy[0]:
del self.accuracy[:]
self.accuracy.append(res)
self.candidate_result = weight
else:
self.accuracy.append(res)
def early_stop(self):
return True if len(self.accuracy) == 20 else False
def get_result(self):
return self.candidate_result
def get_accuracy(self):
return self.accuracy[0]