-
Notifications
You must be signed in to change notification settings - Fork 0
/
performance.py
executable file
·73 lines (65 loc) · 2.01 KB
/
performance.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
#!/usr/bin/python
import numpy as np
import os
import re
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from scipy.cluster.hierarchy import dendrogram, linkage
import csv
import sys
from sklearn.metrics import euclidean_distances
from sklearn import manifold
import random
import itertools
from sklearn.cluster import DBSCAN
seed = np.random.RandomState(seed=3)
markers = ['o', 'v', 'h', 'H', 'o', 'v', 'h', 'H', 'h', 'H', 'o', 'v', 'h']
colors = ['b', 'r','g','c','y','m', 'b', 'r','g','c','y','m','y','m', 'b']
combs = list(itertools.product(markers, colors))
fwrite = open('datasets/performance_models.csv', 'w')
fwrite.write("ID Level_1 Level_2 Level_3 Level_4\n")
dirname = 'clean_data'
users = os.listdir(dirname)
P = {}
D = []
user_models = []
name = []
n = []
for user in users:
sessions = os.listdir(dirname + '/' + user)
NoOfSessions = len(sessions)
for session in sessions:
filename = dirname + '/' + user + '/' + session + '/logfile'
f = open(filename, 'r')
lines = f.readlines()
f.close()
P = {}
scores = []
for line in lines:
a = re.split('\s+', line.strip())
level = abs(int(a[3])) - 1
perf = int(a[4])
rf = int(a[2])
key = tuple([level, rf])
scores.append(int(a[3]))
if P.has_key(key):
P[key].append(perf)
else:
P[key] = [perf]
um = []
for i in [1,2,3,4]:
if scores.count(i) == 0 and scores.count(-1*i) == 0:
um.append(-1.0)
else:
um.append(scores.count(i)/float((scores.count(i) + scores.count(-1*i))))
user_models.append(um)
fwrite.write(user + '/' + session + ' ' + str(um[0]) + ' ' + str(um[1]) + ' ' + str(um[2]) + ' ' + str(um[3]) + '\n')
#print np.mean(user_models, axis=0), np.std(user_models, axis=0)
#X = [1,2,3,4]
#labels = ['Level 1', 'Level 2', 'Level 3', 'Level 4']
#plt.bar(X, np.mean(user_models, axis=0))
#plt.bar(X, np.mean(user_models, axis=0), yerr = np.std(user_models, axis=0), fmt='o--', color = 'b', ecolor='b')
#plt.title("Mean Sucess Probability per Level")
#plt.xticks(X, labels)
#plt.xlim([0,5])
#plt.show()