You are viewing a single comment's thread. Return to all comments →
Can anybody explain, How this question is of expert level?
import math def calc_pearson(x,y): n = len(x) numer = n*sum([a*b for a,b in zip(x,y)]) - sum(x)*sum(y) denom1 = math.sqrt(n*sum([a*a for a in x]) - sum(x)**2) denom2 = math.sqrt(n*sum([a*a for a in y]) - sum(y)**2) return (1.0 * numer)/(denom1*denom2) def main(): n = int(input()) M = [] P = [] C = [] for i in range(n): marks = input().split() marks = [int(a) for a in marks] M.append(marks[0]) P.append(marks[1]) C.append(marks[2]) rMP = calc_pearson(M,P) rPC = calc_pearson(P,C) rCM = calc_pearson(C,M) print("%.2f"%rMP) print("%.2f"%rPC) print("%.2f"%rCM) if(__name__=="__main__"): main()
Seems like cookies are disabled on this browser, please enable them to open this website
Day 5: Computing the Correlation
You are viewing a single comment's thread. Return to all comments →
Can anybody explain, How this question is of expert level?