欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Hackerrank Day 8: Least Square Regression Line

程序员文章站 2022-04-27 12:22:09
...

Hackerrank Day 8: Least Square Regression Line

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))

Hackerrank Day 8: Least Square Regression Line

相关标签: 概率统计