Skip to content

Instantly share code, notes, and snippets.

@Jargon4072
Created June 24, 2020 06:19
Show Gist options
  • Save Jargon4072/cb8fe8970e038e46d801c6be3dc1424c to your computer and use it in GitHub Desktop.
Save Jargon4072/cb8fe8970e038e46d801c6be3dc1424c to your computer and use it in GitHub Desktop.
def run_lr(res,data):
# Note: data should be given in pandas format, as shwon below:
'''
Brain_weight Body_weight
62.00 1320.0
55.50 175.0
35.00 56.0
52.16 440.0
0.28 1.9
'''
points=data
learning_rate = 0.000001
initial_b = 0 # initial y-intercept guess
initial_m = 0 # initial slope guess
num_iterations = 1000
print ("Starting gradient descent at b = {0}, m = {1}, error = {2}".format(initial_b, initial_m, compute_error_for_line_given_points(initial_b, initial_m, array(points))))
print ("Running...")
[b, m] = gradient_descent_runner(points, initial_b, initial_m, learning_rate, num_iterations)
print ("After {0} iterations b = {1}, m = {2}, error = {3}".format(num_iterations, b, m, compute_error_for_line_given_points(b, m, array(points))))
print(b)
print(m)
res.append(b)
res.append(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment