You are viewing a single comment's thread. Return to all comments →
import math line1 = "Physics Scores 15 12 8 8 7 7 7 6 5 3" line2 = "History Scores 10 25 17 11 13 17 20 13 9 15" x = [int(e) for e in line1.split()[2:]] y = [int(e) for e in line2.split()[2:]] n = len(x) ex = sum(x)/n ey = sum(y)/n cov = sum([(xi-ex)*(yi-ey) for (xi,yi) in zip(x,y)]) stdx = math.sqrt(sum([(xi-ex)**2 for xi in x])) stdy = math.sqrt(sum([(yi-ey)**2 for yi in y])) result = cov/(stdx*stdy) print(f"{result:.3f}")
Seems like cookies are disabled on this browser, please enable them to open this website
Correlation and Regression Lines - A Quick Recap #1
You are viewing a single comment's thread. Return to all comments →