Hackerrank Day 8: Least Square Regression Line
程序员文章站
2022-04-27 12:22:09
...
n = 5
xy = [list(map(int, input().split())) for _ in range(n)]
'''
print(xy)
for x,y in xy:
print(x,end=', ')
print(y)
'''
sx, sy, sx2, sxy = map(sum, zip(*[(x, y, x**2, x * y) for x, y in xy]))
b = (n * sxy - sx * sy) / (n * sx2 - sx**2)
a = (sy / n) - b * (sx / n)
print('{:.3f}'.format(a + b * 80))