You are viewing a single comment's thread. Return to all comments →
from math import sqrt x = int(input()) scores = [list(map(lambda a : float(a), input().split('\t'))) for _ in range(x)] m = list(map(lambda a : a[0], scores)) p = list(map(lambda a : a[1], scores)) c = list(map(lambda a : a[2], scores)) def correlation(X, Y, N): numerator = (N * sum(map(lambda a,b : a*b, X, Y))) - (sum(X)*sum(Y)) denominator = sqrt(N*sum(map(lambda a : a**2, X)) - (sum(X)**2)) * sqrt(N*sum(map(lambda a : a**2, Y)) - (sum(Y)**2)) return numerator/denominator print('%.2f'%(correlation(m,p,x))) print('%.2f'%(correlation(p,c,x))) print('%.2f'%(correlation(c,m,x)))
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 →