-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathaccuracy.py
43 lines (37 loc) · 1.08 KB
/
accuracy.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
import time
import math
import sys
usage = "filename labels_1 labels_2 feature_index"
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
def accuracy(s1,s2,threshold,feature_index):
line_count = file_len(s1)
f1 = open(s1,'r')
f2 = open(s2,'r')
count = 0
try:
for i in xrange(line_count):
a = float(f1.readline())
b = float(f2.readline())
if((a<=threshold and b<=threshold)or(a>threshold and b>threshold)):
f3.write("1")
count = count + 1
else:
f3.write("0")
if(float(feature_index)%4!=0):
print("%0.2f\t"%((count*1.0/line_count)*100.0))
else:
print("%0.2f\t\n"%((count*1.0/line_count)*100.0))
except IOError:
print("Error: IOError at count %d "%count)
f1.close()
f2.close()
def main():
if (len(sys.argv)!=4):
print usage
else:
accuracy(sys.argv[1],sys.argv[2],4.5,sys.argv[3])
if __name__ == "__main__":main()