forked from RockStarCoders/alienMarkovNetworks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowFeatures.py
executable file
·70 lines (55 loc) · 1.9 KB
/
showFeatures.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
#!/usr/bin/env python
'''
Display features in the given binary file. Mainly for debugging.
see testFeatures.py
'''
import argparse
parser = argparse.ArgumentParser(description='Show features in binary file')
parser.add_argument('ftrs', type=str, action='store', \
help='filename of pkl or csv features data')
parser.add_argument('--labs', type=str, action='store', default=None,\
help='filename of pkl or csv training labels data. Optional.')
parser.add_argument('--nshow', type=int, default=3,\
help='Max number of features to show at once on scatter plot grid')
parser.add_argument('--nstart', type=int, default=0,\
help='Index of feature to start at')
args = parser.parse_args()
import amntools
import matplotlib.pyplot as plt
import pomio
plt.interactive(1)
# Load the features and labels
if args.ftrs.endswith('.pkl'):
ftrs = pomio.unpickleObject( args.ftrs )
else:
ftrs = pomio.readMatFromCSV( args.ftrs )
N = ftrs.shape[0]
D = ftrs.shape[1]
print '%d feature vectors of dimensionality = %d' % (N,D)
if args.labs == None:
labs = None
else:
if args.labs.endswith('.pkl'):
labs = pomio.unpickleObject( args.labs )
else:
labs = pomio.readMatFromCSV( args.labs ).astype(np.int32)
# show labels
if labs != None:
plt.figure()
plt.hist( labs, pomio.getNumClasses() )
plt.title('Class counts')
plt.xticks( range(pomio.getNumClasses()),
pomio.getClasses()[:pomio.getNumClasses()],
size='small' )
# show at most 9 features at once
fstarts = range( args.nstart, D, args.nshow )
plt.figure()
for fs in fstarts:
fend = min(D-1,fs+args.nshow-1)
print ' Displaying features %d-%d:' % (fs, fend)
rng = range( fs, fend+1 )
fnames = [ 'F%d' % x for x in rng ]
amntools.gplotmatrix( ftrs[:,rng], labs, featureNames=fnames )
plt.waitforbuttonpress()
plt.interactive(0)
plt.show()