Created
March 22, 2019 20:04
-
-
Save Anton-Cao/eb99f061701c0a294b7a234ccecd40ac to your computer and use it in GitHub Desktop.
Pseudocode for perceptron algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def perceptron(data, labels): | |
""" | |
Pseudo-python for perceptron algorithm | |
""" | |
d, n = data.dims # data is d x n array | |
th = [0] * n # initialize theta to vector of zeros | |
th_0 = 0 | |
while True: | |
done = True | |
for i in range(d): | |
if labels[i] * (th * data[i] + th_0) <= 0: # check for misclassification | |
th += labels[i] * data[i] | |
th_0 += labels[i] | |
done = False | |
if done: break # stop when no mistakes are made on entire dataset | |
return (th, th_0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment