-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiris_test_reducer.py
executable file
·151 lines (126 loc) · 2.9 KB
/
iris_test_reducer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
import sys
import base64
import cPickle as pickle
#from mrjob.job import MRJob
import numpy as np
def main():
tp=0
tn=0
fn=0
fp=0
count2 = 0
old_key = 0
classes_pos_list = []
classes_neg_list = []
accuracy_list = []
omegalist = []
gammalist = []
for line in sys.stdin:
#print line
line = line.strip()
line = line.replace('[', '')
line = line.replace(']', '')
line = line.split('$')
#print line
key = int(line[0])
#print key
if(key == old_key):
#print line
#print line[7]
tp = tp + int(line[1])
fp = fp + int(line[2])
fn = fn + int(line[3])
tn = tn + int(line[4])
#x =line[1]
#y=line[2]
#om = line[7]
#gam = line[8]
old_key = key
#print tp,fp,fn,tn
else:
#omegalist.append(om)
#gammalist.append(gam)
'''
classes_pos_list.append(x)
x = classes_pos_list[-1]
x = x.replace('\'', '')
x = x.replace(' ', '')
classes_pos_list[-1] = x
classes_neg_list.append(y)
x = classes_neg_list[-1]
x = x.replace('\'', '')
x = x.replace(' ', '')
classes_neg_list[-1] = x
'''
if (tp==0 and fp ==0):
precision = 0.0
else:
precision = float(tp)/(tp+fp)
if (tp==0 and fn ==0):
recall = 0.0
else:
recall = float(tp)/(tp+fn)
if (precision ==0.0 and recall ==0.0):
f1measure = 0
else:
f1measure = 2*precision*recall/(precision+recall)
accuracy = float(tp+tn)/(tp+tn+fn+fp)
accuracy_list.append(str(accuracy))
#print line[1], line[2], precision, recall, f1measure, accuracy
tp=0
tn=0
fn=0
fp=0
tp = tp + int(line[1])
fp = fp + int(line[2])
fn = fn + int(line[3])
tn = tn + int(line[4])
#x = line[1]
#y=line[2]
#om = line[7]
#gam = line[8]
#print tp,fp,fn,tn
old_key = key
'''
omegalist.append(om)
gammalist.append(gam)
classes_pos_list.append(x)
x = classes_pos_list[-1]
x = x.replace('\'', '')
x = x.replace(' ', '')
classes_pos_list[-1] = x
classes_neg_list.append(y)
x = classes_neg_list[-1]
x = x.replace('\'', '')
x = x.replace(' ', '')
classes_neg_list[-1] = x
'''
if (tp==0 and fp ==0):
precision = 0.0
else:
precision = float(tp)/(tp+fp)
if (tp==0 and fn ==0):
recall = 0.0
else:
recall = float(tp)/(tp+fn)
if (precision ==0.0 and recall ==0.0):
f1measure = 0
else:
f1measure = 2*precision*recall/(precision+recall)
accuracy = float(tp+tn)/(tp+tn+fn+fp)
accuracy_list.append(str(accuracy))
#print accuracy_list, omegalist, gammalist
max=0
index = 0
for i in range(len(accuracy_list)):
accuracy_list[i] = float(accuracy_list[i])
if(accuracy_list[i]>max):
max=accuracy_list[i]
index = i
print accuracy_list[index]
#print classes_pos_list, classes_neg_list
#print "sas", classes_list, "lkl", accuracy_list
#print line[1], line[2], precision, recall, f1measure, accuracy
#print key, precision, recall, f1measure, accuracy
main()