-
Notifications
You must be signed in to change notification settings - Fork 1
/
Keystroke_Manhattan.py
55 lines (44 loc) · 1.9 KB
/
Keystroke_Manhattan.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
#Keystroke_Manhattan.py
from scipy.spatial.distance import cityblock
import numpy as np
np.set_printoptions(suppress = True)
import pandas
from EER import evaluateEER
class ManhattanDetector:
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
def testing(self):
for i in range(self.test_genuine.shape[0]):
cur_score = cityblock(self.test_genuine.iloc[i].values, \
self.mean_vector)
self.user_scores.append(cur_score)
for i in range(self.test_imposter.shape[0]):
cur_score = cityblock(self.test_imposter.iloc[i].values, \
self.mean_vector)
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 detector:"
print(ManhattanDetector(subjects).evaluate())