-
Notifications
You must be signed in to change notification settings - Fork 0
/
ml.py
85 lines (67 loc) · 1.79 KB
/
ml.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
#from sklearn import tree,svm
import numpy as np
from LogReader import LogReader
import matplotlib.pyplot as plt
data1=LogReader("manasLog.txt")
data2=LogReader("khalidLog.txt")
data3=LogReader("bhoomiLog.txt")
gaussian_numbers = np.random.randn(1000)
a=[]
b=[]
c=[]
x=[0,1,2,3,4,5,6,7]
keys=["NULL","UP","LEFT","RIGHT","DOWN","CTRL","SPACE"]
for i in data1.rawFeatures:
a.append(i[0])
for i in data2.rawFeatures:
b.append(i[0])
for i in data3.rawFeatures:
c.append(i[0])
plt.figure(1)
plt.title("Times keys pressed")
plt.xlabel("key")
plt.ylabel("Frequency")
plt.xticks(x,keys)
plt.hist([a,b,c],x,label=['Manas','Khalid','Bhoomi'],align='left')
plt.legend()
fig, ax = plt.subplots()
nGroups=7
barWidth=0.35
plt.title("Duration of key presses")
index=np.arange(nGroups)
y=[data1.totalKeyPressTimes,data2.totalKeyPressTimes,data3.totalKeyPressTimes]
rec1=ax.bar(index+.1,y[0],barWidth,color='b',label='Manas',align='center')
rec2=ax.bar(index+barWidth,y[1],barWidth,color='g',label='Khalid',align='center')
rec3=ax.bar(index+2*barWidth,y[2],barWidth,color='r',label='Bhoomi',align='center')
plt.xlabel('Keys')
plt.ylabel('Duration in seconds')
ax.set_xticks(index)
ax.set_xticklabels(keys)
ax.legend()
plt.show()
#data1.printData()
#data2.printData()
'''
featuresNormal,featuresRash=addPadding(featuresNormal,featuresRash)
addPadding(featuresNormal,featuresTest)
#print len(featuresTestN)
features=[featuresNormal,featuresRash]
#print features
labels=[0,1]#0=normal, 1=rash driver
print featuresNormal
clf=tree.DecisionTreeClassifier()
n=0
r=0
for i in range (0,1000):
clf=clf.fit(features,labels)
p=clf.predict([featuresTest])
print p
#s=svm.SVC()
#s=s.fit(features,labels)
#p=s.predict([featuresTest])
if p==[0]:
n=n+1.0
else:
r=r+1.0
print "n is ",n," r is ",r
print "n/(n+r) is ",n/(n+r)'''