Skip to content

Instantly share code, notes, and snippets.

@skyer9
Created April 22, 2017 11:05
Show Gist options
  • Save skyer9/eb8885a9dcf225ede2bc28ff083519fa to your computer and use it in GitHub Desktop.
Save skyer9/eb8885a9dcf225ede2bc28ff083519fa to your computer and use it in GitHub Desktop.
x_train = [1., 2., 3., 4.]
y_train = [1.1, 2.1, 3.1, 4.1]
W, b = 123, 45
learning_rate = 0.05
for epoch in range(0, 200):
for j in range(0, len(x_train)):
cal_y = W * x_train[j] + b
error = (cal_y - y_train[j])
W = W - learning_rate * x_train[j] * error
b = b - learning_rate * error
print('epoch: %i, W:%f, b:%f' % ((epoch + 1), W, b))
print('result W * 5 + b = %f' % (W * 5 + b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment