File size: 527 Bytes
96283ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import math


def sampleStandardDeviation(x):
	"""calculates the sample standard deviation"""
	sumv = 0.0
	for i in x:
		sumv += (i) ** 2
	return math.sqrt(sumv / (len(x) - 1))


def pearson(x, y):
	"""calculates the PCC"""
	scorex, scorey = [], []
	for i in x:
		scorex.append((i) / sampleStandardDeviation(x))
	for j in y:
		scorey.append((j) / sampleStandardDeviation(y))
	# multiplies both lists together into 1 list (hence zip) and sums the whole list
	return (sum([i * j for i, j in zip(scorex, scorey)])) / (len(x) - 1)