-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKeystroke_ManhattanScaled.py
More file actions
63 lines (52 loc) · 2.34 KB
/
Keystroke_ManhattanScaled.py
File metadata and controls
63 lines (52 loc) · 2.34 KB
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
#keystroke_ManhattanFiltered.py
import numpy as np
np.set_printoptions(suppress = True)
import pandas
from EER import evaluateEER
class ManhattanScaledDetector:
#just the training() function changes, rest all remains same.
def __init__(self, subjects):
self.user_scores = []
self.imposter_scores = []
self.mean_vector = []
self.subjects = subjects
def training(self):
self.mean_vector = self.train.mean().values
#also calculating mean absolute deviation deviation of each feature
self.mad_vector = self.train.mad().values
def testing(self):
for i in range(self.test_genuine.shape[0]):
cur_score = 0
for j in range(len(self.mean_vector)):
cur_score = cur_score + \
abs(self.test_genuine.iloc[i].values[j] - \
self.mean_vector[j]) / self.mad_vector[j]
self.user_scores.append(cur_score)
for i in range(self.test_imposter.shape[0]):
cur_score = 0
for j in range(len(self.mean_vector)):
cur_score = cur_score + \
abs(self.test_imposter.iloc[i].values[j] - \
self.mean_vector[j]) / self.mad_vector[j]
self.imposter_scores.append(cur_score)
def evaluate(self):
eers = []
for subject in subjects:
genuine_user_data = data.loc[data.subject == subject, \
"H.period":"H.Return"]
imposter_data = data.loc[data.subject != subject, :]
self.train = genuine_user_data[:200]
self.test_genuine = genuine_user_data[200:]
self.test_imposter = imposter_data.groupby("subject"). \
head(5).loc[:, "H.period":"H.Return"]
self.training()
self.testing()
eers.append(evaluateEER(self.user_scores, \
self.imposter_scores))
return np.mean(eers)
path = os.path.dirname( os.path.realpath(__file__) )
data_path = os.path.join(path, 'keystroke.csv')
data = pandas.read_csv(data_path)
subjects = data["subject"].unique()
print "average EER for Manhattan Scaled detector:"
print(ManhattanScaledDetector(subjects).evaluate())