Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created November 13, 2011 12:54
Show Gist options
  • Save marcelcaraciolo/1362087 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/1362087 to your computer and use it in GitHub Desktop.
Logistic prediction
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)
@waylonflinn
Copy link

Simplified version of this one:

def predict(theta, X, y):
    p_1 = sigmoid(numpy.dot(X, theta))
    return p_1 > 0.5

You can run it just as shown above.

@bdss58
Copy link

bdss58 commented Dec 17, 2014

@waylonflinn nice!

@yuuniverse4444
Copy link

Beautiful :)

@jamesbondo
Copy link

Where's the full set of code please?..

@ajaychawda58
Copy link

p = predict(array(theta), it)
I am getting a name error: theta not defined

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