-
Notifications
You must be signed in to change notification settings - Fork 2
/
CalculateCorrelation.py
51 lines (35 loc) · 1.53 KB
/
CalculateCorrelation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pandas as pd
import sys
import glob
import os
import os.path
from numpy import unique
from numpy import mean
from pandas import DataFrame, Series
import matplotlib.pyplot as plt
from collections import OrderedDict
import operator
class CalculateCorrelation:
subjectFileName="Subject30.csv"
allFileName="MOSandGeneralFileNameWithHeader.csv"
def __init__(self, master=None):
if sys.platform.startswith('win'):
self.subjectinputdir="<MergeDir>"
self.allinputdir="<ACRScoresDir>"
elif sys.platform.startswith('darwin'):
self.subjectinputdir="<MergeDir>"
self.allinputdir="<ACRScoresDir>"
self.subjectDF=pd.read_csv(self.subjectinputdir+self.subjectFileName,index_col=None, header=0)
self.allDF=pd.read_csv(self.allinputdir+self.allFileName,index_col=None, header=0)
def calculate(self):
#print self.subjectDF
#print self.allDF
ind = self.allDF['GeneralFileName'].isin(self.subjectDF['GeneralFileName'])
#print ind
allSortedDF=self.allDF[ind].sort(['GeneralFileName'])
subjectSortedDF=self.subjectDF.sort(['GeneralFileName'])
result = pd.merge(allSortedDF, subjectSortedDF, on=['GeneralFileName', 'GeneralFileName'])
print str(len(subjectSortedDF))+","+str(result['MOS_x'].corr(result['MOS_y']))
if __name__ == "__main__":
calculateCorrelation = CalculateCorrelation()
calculateCorrelation.calculate()