-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplotBoundary.py
26 lines (24 loc) · 1.04 KB
/
plotBoundary.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
import pdb
from numpy import *
import pylab as pl
# X is data matrix (each row is a data point)
# Y is desired output (1 or -1)
# scoreFn is a function of a data point
# values is a list of values to plot
def plotDecisionBoundary(X, Y, scoreFn, values, title = "", meshsize=200.):
# Plot the decision boundary. For that, we will asign a score to
# each point in the mesh [x_min, m_max]x[y_min, y_max].
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
h = max((x_max-x_min)/meshsize, (y_max-y_min)/meshsize)
xx, yy = meshgrid(arange(x_min, x_max, h),
arange(y_min, y_max, h))
zz = array([scoreFn(x) for x in c_[xx.ravel(), yy.ravel()]])
zz = zz.reshape(xx.shape)
pl.figure()
CS = pl.contour(xx, yy, zz, values, colors = 'green', linestyles = 'solid', linewidths = 2)
pl.clabel(CS, fontsize=9, inline=1)
# Plot the training points
pl.scatter(X[:, 0], X[:, 1], c=(1.-Y), s=50, cmap = pl.cm.cool)
pl.title(title)
pl.axis('tight')