Some error occured while loading page for you. Please try again.
You are viewing a single comment's thread. Return to all comments →
I am pretty sure this is correct but stdout is printing 'None' after I print out the coefficients. Additionally, computing statistics and machine learning related problems from stdin is silly. You simply do not manipulate data in this way in this kind of work, I do this type of work everyday; every question related to these topics should come with datasets that you load; not where you load each line from stdin or iterate over stdin, it is bizarre and irrelevant to this kind of work.
*edit removing the print statements fixes the problem.
N = int(raw_input())
grades = 
for _ in range(N):
grades.append([int(b) for b in raw_input().split('\t')])
m = [int(b) for b in grades]
p = [int(b) for b in grades]
c = [int(b) for b in grades]
def pearson(A, B, N):
sumA = sum(A)
sumB = sum(B)
AB = sum([x*y for x,y in zip(A, B)])
A_sq = sum([x**2 for x in A])
B_sq = sum([x**2 for x in B])
numerator = (N*(AB) - sumA*sumB)
denominator = (math.sqrt((N*A_sq - sumA**2) * (N*B_sq - sumB**2)))
print round(numerator/denominator, 2)
co1 = pearson(m, p, N)
co2 = pearson(p, c, N)
co3 = pearson(c, m, N)