2 from sklearn
import manifold, svm, preprocessing
4 from mpl_toolkits.mplot3d
import Axes3D
5 from matplotlib.ticker
import NullFormatter
9 slist = open(scorename,
'r').readlines()
10 glist = open(gradname, 'r').readlines()
14 for s, g
in zip(slist, glist):
15 sval = float(s.split()[0])
16 if(np.isfinite(sval)):
17 skeep.append(np.fromstring(s, sep=
' '))
18 nar = np.fromstring(g, sep=
' ')
20 return (np.vstack(skeep), np.vstack(gkeep))
23 (scores, grads) =
read_data(
"grad_data.out",
"score_data.out")
24 (scores2, grads2) =
read_data(
"grad_data2.out",
"score_data2.out")
27 scaler =preprocessing.StandardScaler().fit(grads);
29 grads = scaler.transform(grads)
30 grads2 = scaler.transform(grads2)
35 test_svm = svm.SVC(kernel=
'rbf', C=20, gamma=0.15, probability=
True)
36 test_svm=test_svm.fit(Y, scores[:, 1])
41 (Y, scores) = grads2, scores2
42 num_stab = sum(1
for s
in scores
if s[1] == 1)
43 missed_stab_arr = [s[0]
for t, s,
in zip(Y, scores)
if s[1]==1
and test_svm.predict(t) != s[1]]
44 pl.hist(missed_stab_arr, bins=20)
45 pl.title(
"Frequency of scores for the misclassified stable solutions")
47 missed_stab = len(missed_stab_arr)
48 ave_score = sum(missed_stab_arr)/len(missed_stab_arr);
49 max_score =
max(missed_stab_arr)
50 missed_stab_arr = [s[0]
for t, s,
in zip(Y, scores)
if s[1]==1
and test_svm.predict(t) == s[1]]
52 pl.hist(missed_stab_arr, bins=50, color=
'green')
53 pl.title(
"Frequency of scores for the correctly classified stable solutions")
55 ave_good_score = sum(missed_stab_arr)/len(missed_stab_arr);
56 max_good_score =
max(missed_stab_arr)
58 print "%d out of %d stable solutions were missclassified" %(missed_stab, num_stab)
59 print "Average score of the missclassified stable variables is %f, maximum score is %f" % (ave_score, max_score)
60 print "Average score of the classified stable variables is %f, maximum score is %f" % (ave_good_score, max_good_score)
63 num_unstab = sum(1
for s
in scores
if s[1] == 0)
64 missed_unstab = sum(1
for t, s
in zip(Y, scores)
if s[1] == 0
and test_svm.predict(t) != s[1])
65 print "%d out of %d unstable solutions were missclassified" %(missed_unstab, num_unstab)
69 fig = pl.figure(figsize=(15, 8))
70 pl.suptitle("Manifold Learning with %i points, %i neighbors"
71 % (grads.shape[1], n_neighbors), fontsize=14)
74 # compatibility matplotlib < 1.0
75 ax = fig.add_subplot(241, projection='3d')
76 ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], c=scores[:, 0], cmap=pl.cm.Spectral)
79 #pl.scatter(Y[:, 0], Y[:, 1], Y[:, 2], c=scores, cmap=pl.cm.Spectral)