Created
October 7, 2019 21:33
-
-
Save bobbywlindsey/6097232bd1898a17e4977b3473c5e185 to your computer and use it in GitHub Desktop.
Perceptron update weights with algo 2: weights = weights + error * vector
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
weights = initialize_weights(train_data.shape[1]) | |
for epoch in range(3): | |
sum_of_squared_errors = 0.0 | |
for sample in range(train_data.shape[0]): | |
vector = train_data.loc[sample].values | |
label = train_label.loc[sample] | |
if label == 0: label = -1 | |
prediction = predict(vector, weights, 'sign') | |
error = label - prediction | |
sum_of_squared_errors += error**2 | |
weights = weights + error * vector | |
print(f'SSE: {sum_of_squared_errors}') | |
print(f'Weights: {weights}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment