-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclassifier1.py
52 lines (44 loc) · 1.16 KB
/
classifier1.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
from operator import itemgetter
import math
def euclid_dist(a,b):
res=0.0
for i in range(1,49):
res+=(float(a[i])-float(b[i]))*(float(a[i])-float(b[i]))
return math.sqrt(res)
def trueLabel(frame):
for i in posture1:
if int(frame)>= i[0] and int(frame)<= i[1]:
return 1
for i in posture2:
if int(frame)>= i[0] and int(frame)<= i[1]:
return 2
for i in posture3:
if int(frame)>= i[0] and int(frame)<= i[1]:
return 3
f=open('bsplineder.txt','r')
frames=f.readlines()
posture1=[(0,93),(131,175),(213,256),(297,344),(385,428),(465,508),(548,588),(627,674),(709,753)]
posture2=[(94,130),(257,296),(429,464),(589,626)]
posture3=[(176,212),(345,384),(509,547),(675,708)]
a=dict()
for feature in open('features.csv'):
l=feature.split(',')
a[l[0]]=l
test_label=dict()
c=0
c1=0
for feature in open('features.csv'):
l=feature.split(',')
dist=[]
for frame in frames:
frame=frame.rstrip()
d=euclid_dist(l,a[frame])
dist.append((frame,d))
dist=sorted(dist,key=itemgetter(1))
test_label[l[0]]=trueLabel(dist[0][0])
#print l[0]
print test_label[l[0]],trueLabel(l[0])
if test_label[l[0]]==trueLabel(l[0]):
c1+=1
c+=1
print (c1*100.0)/(c)