Thank you for your help! I changed the code as you suggested, but I still get the same mistake - line15 in Mean1
'list' object has no attribute 'a'. Do you know if I enter lists correctly?
Thank you for your help!
'list' object has no attribute 'a'. Do you know if I enter lists correctly?
Thank you for your help!
import math class Correlation: def __init__(self, a = [], b = []): self.a = a self.b = b def getA(self): return self.a def getB(self): return self.b def Mean1(self): tsum = 0 for x in range(0, len(self.a)): tsum = tsum + self.a[x] return tsum/len(self.a) def Mean2(self): tsum = 0 for x in range(0, len(self.b)): tsum = tsum + self.b[x] return tsum/len(self.b) def Sample_Standard_Deviation1(self): Mean_of_L1 = Correlation.Mean1(self.a) tsum = 0 for x in range(0, len(self.a)): tsum = tsum + (self.a[x] - Mean_of_L1) ** 2 return math.sqrt(tsum / (len(self.a) - 1)) def Sample_Standard_Deviation2(self): Mean_of_L1 = Correlation.Mean2(self.b) tsum = 0 for x in range(0, len(self.b)): tsum = tsum + (self.a[x] - Mean_of_L1) ** 2 return math.sqrt(tsum / (len(self.b) - 1)) def Correlation_Coefficient(self): meanx = self.Mean1() meany = self.Mean2() stdx = self.Sample_Standard_Deviation1() stdy = self.Sample_Standard_Deviation2() tsum = 0 for idx in range(0,len(self.a)): tsum = tsum + ((self.a[idx] - meanx)/stdx) * ((self.b[idx] - meany) / stdy) return tsum / (len(self.a) - 1)
import Correlation as c x = [1,2,3] y = [10,20,30] c1 = c.Correlation(x, y) print("Correlation is %.2f" % c1.Correlation_Coefficient())