Skip to content

Instantly share code, notes, and snippets.

@Jargon4072
Created June 24, 2020 04:00
Show Gist options
  • Save Jargon4072/a7b19614c9a9f23338641d2bb3981bc3 to your computer and use it in GitHub Desktop.
Save Jargon4072/a7b19614c9a9f23338641d2bb3981bc3 to your computer and use it in GitHub Desktop.
from numpy import *
# y = mx + b
# m is slope, b is y-intercept
# point is tuple of x,y value at a given step with data as points[i]= [xi, yi]
def compute_error_for_line_given_points(b, m, points):
totalError = 0
for i in range(0, len(points)):
x = points[i, 0]
y = points[i, 1]
totalError += (y - (m * x + b)) ** 2
return totalError / float(len(points))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment