-
Notifications
You must be signed in to change notification settings - Fork 1
/
visualize_clf.py
executable file
·65 lines (61 loc) · 1.66 KB
/
visualize_clf.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
#!/usr/bin/python
from matplotlib import pyplot as plt
import numpy as np
import pickle
from glob2 import glob
from scipy import ndimage
import sys
def visualize_clf(file_path):
ext_pattern = "14"
int_pattern = "23"
path = "{}/**/*{}*.p".format(file_path,ext_pattern)
files = glob(path)
print files
thresholds = np.arange(0.65,1,0.05)
file_dict = dict()
for f in files:
filename = f[f.rfind('/')+1:]
sub = filename[:filename.find('_')]
pair = (f,f.replace(ext_pattern,int_pattern))
print pair
if sub in file_dict:
file_dict[sub].append(pair)
else:
file_dict[sub]=[pair]
print file_dict
for sub,file_list in file_dict.iteritems():
fig = plt.figure()
cell_text = []
col_labels= []
file_list = sorted(file_list)
for i,pair in enumerate(file_list):
print pair
f = pair[0]
sl = pickle.load(open(f,'rb'))
data = sl.samples[0]
fig.add_subplot(4,4,i+1)
title = f[f.find('-')+1:]
plt.title(title)
col_labels.append(title)
plt.hist(data)
coltext = []
print title
for thr in thresholds:
data_3d = sl.a.mapper.reverse1(sl.samples)[0]
cluster_map, n_clusters = ndimage.label(data_3d > thr)
cluster_sizes = np.bincount(cluster_map.ravel())[1:]
if len(cluster_sizes) != 0:
coltext.append("{}".format(np.max(cluster_sizes)))
else:
coltext.append(0)
cell_text.append(coltext)
ax = fig.add_subplot(4,4,len(files)+2)
ax.axis('off')
print len(cell_text)
plt.table(cellText= cell_text,rowLabels=col_labels,
colLabels=thresholds,loc='center right')
plt.savefig('{}.png'.format(sub))
if __name__ == '__main__':
path = str(sys.argv[1])
visualize_clf(path)
raw_input()