Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created November 15, 2011 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marcelcaraciolo/1365849 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/1365849 to your computer and use it in GitHub Desktop.
decision_boundary.py
#Plot Boundary
u = linspace(-1, 1.5, 50)
v = linspace(-1, 1.5, 50)
z = zeros(shape=(len(u), len(v)))
for i in range(len(u)):
for j in range(len(v)):
z[i, j] = (map_feature(array(u[i]), array(v[j])).dot(array(theta)))
z = z.T
contour(u, v, z)
title('lambda = %f' % l)
xlabel('Microchip Test 1')
ylabel('Microchip Test 2')
legend(['y = 1', 'y = 0', 'Decision boundary'])
show()
def predict(theta, X):
'''Predict whether the label
is 0 or 1 using learned logistic
regression parameters '''
m, n = X.shape
p = zeros(shape=(m, 1))
h = sigmoid(X.dot(theta.T))
for it in range(0, h.shape[0]):
if h[it] > 0.5:
p[it, 0] = 1
else:
p[it, 0] = 0
return p
#% Compute accuracy on our training set
p = predict(array(theta), it)
print 'Train Accuracy: %f' % ((y[where(p == y)].size / float(y.size)) * 100.0)
@jamesbondo
Copy link

how do you tell which contour line is the real decision boundary? since there are so many of them...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment