Skip to content

Instantly share code, notes, and snippets.

@bobbywlindsey
Created October 7, 2019 21:32
Show Gist options
  • Save bobbywlindsey/826fafa1610e8fa3794d4247db8dde95 to your computer and use it in GitHub Desktop.
Save bobbywlindsey/826fafa1610e8fa3794d4247db8dde95 to your computer and use it in GitHub Desktop.
Perceptron update weights with algo 1: weights = weights + label * vector
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
if error != 0:
weights = weights + label * 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