- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_vis.py
More file actions
Latest commit
60 lines (47 loc) · 1.76 KB
/
Copy pathclass_vis.py
File metadata and controls
60 lines (47 loc) · 1.76 KB
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
#!/usr/bin/python
#from udacityplots import *
importwarnings
warnings.filterwarnings("ignore")
importmatplotlib
matplotlib.use('agg')
importmatplotlib.pyplotasplt
importpylabaspl
importnumpyasnp
#import numpy as np
#import matplotlib.pyplot as plt
#plt.ioff()
defprettyPicture(clf, X_test, y_test):
x_min=0.0; x_max=1.0
y_min=0.0; y_max=1.0
# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, m_max]x[y_min, y_max].
h=.01# step size in the mesh
xx, yy=np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z=clf.predict(np.c_[xx.ravel(), yy.ravel()])
# Put the result into a color plot
Z=Z.reshape(xx.shape)
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.pcolormesh(xx, yy, Z, cmap=pl.cm.seismic)
# Plot also the test points
grade_sig= [X_test[ii][0] foriiinrange(0, len(X_test)) ify_test[ii]==0]
bumpy_sig= [X_test[ii][1] foriiinrange(0, len(X_test)) ify_test[ii]==0]
grade_bkg= [X_test[ii][0] foriiinrange(0, len(X_test)) ify_test[ii]==1]
bumpy_bkg= [X_test[ii][1] foriiinrange(0, len(X_test)) ify_test[ii]==1]
plt.scatter(grade_sig, bumpy_sig, color="b", label="fast")
plt.scatter(grade_bkg, bumpy_bkg, color="r", label="slow")
plt.legend()
plt.xlabel("bumpiness")
plt.ylabel("grade")
plt.savefig("test.png")
importbase64
importjson
importsubprocess
defoutput_image(name, format, bytes):
image_start="BEGIN_IMAGE_f9825uweof8jw9fj4r8"
image_end="END_IMAGE_0238jfw08fjsiufhw8frs"
data= {}
data['name'] =name
data['format'] =format
data['bytes'] =base64.encodestring(bytes)
printimage_start+json.dumps(data)+image_end