Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bobbywlindsey/cb4b3707765c73d261f83c4ea500de91 to your computer and use it in GitHub Desktop.
Save bobbywlindsey/cb4b3707765c73d261f83c4ea500de91 to your computer and use it in GitHub Desktop.
Three iterations of updates for perceptron weights
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]
prediction = predict(vector, weights, 'step')
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