Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created February 19, 2018 13:21
Show Gist options
  • Save hackintoshrao/fd080c67405f694f1a481558c275be92 to your computer and use it in GitHub Desktop.
Save hackintoshrao/fd080c67405f694f1a481558c275be92 to your computer and use it in GitHub Desktop.
optimizing for case 1 and 2.
def parameter_optimize(x1, x2, y, w1=w1,w2=w2, b=b, learning_rate = learning_rate):
# X contains the 100 student records.
# Iterate through each record.
for i in range(len(x1)):
# Make prediction using the initial values of W[0], W[1], b.
y_hat = find_perceptron_prediction(x1[i], x2[i], w1, w2, b)
# Case where the red points are wrongly classified.
# This is the case where the actual output is 0 but the prediction is 1.
if y[i] != y_hat and y[i] == 0:
w1 = w1 - test_scores[i] * learning_rate
w2 = w2 - grades[i] * learning_rate
b = b - learning_rate
# Case where the green points are wrongly classified.
# This is the case where the actual output is 0 but the prediction is 1.
if y[i] != y_hat and y[i] == 1:
w1 = w1 + test_scores[i] * learning_rate
w2 = w2 + grades[i] * learning_rate
b = b + learning_rate
return w1, w2, b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment