Skip to content

Instantly share code, notes, and snippets.

@marciok
Created August 7, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marciok/fbbf27c8a6f7dee41d11eae8d428ea01 to your computer and use it in GitHub Desktop.
Save marciok/fbbf27c8a6f7dee41d11eae8d428ea01 to your computer and use it in GitHub Desktop.
def calculate_error(points, m, b):
# Error is calculated by the average distance from the points to the line
error = 0
for i in range(0, len(points)):
x = points[i, 0]
y = points[i, 1]
# Moving y to the other side of the equation
# y = mx + b -> = mx + b - y
error += (y - (m*x + b))**2
# Calculating average
return error / float(len(points))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment