Skip to content

Instantly share code, notes, and snippets.

@antondevv
Last active September 22, 2021 12:41
Show Gist options
  • Save antondevv/fef481b01868f4c0b1cee39e33b67ee6 to your computer and use it in GitHub Desktop.
Save antondevv/fef481b01868f4c0b1cee39e33b67ee6 to your computer and use it in GitHub Desktop.
cost_function
def cost_function(m, b, points):
the_total_error = 0
sum_error = 0
for i in range(len(points)):
x = points.iloc[i].weight
y = points.iloc[i].height
the_total_error += (y - (m * x + b)) ** 2
sum_error += the_total_error
print(sum_error)
return sum_error
for i in range(-2, 2):
cost_function(i, i, data)
#What we get when it prints:
#645
#324
#113
#12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment