from math import sqrt def multipl(a,b): sumofab=0.0 for i in range(len(a)): temp=a[i]*b[i] sumofab+=temp return sumofab def corrcoef(x,y): n=len(x) #求和 sum1=sum(x) sum2=sum(y) #求乘积之和 sumofxy=multipl(x,y) #求平方和 sumofx2 = sum([pow(i,2) for i in x]) sum
template <class T1, class T2>double Pearson(std::vector<T1> &inst1, std::vector<T2> &inst2) { if(inst1.size() != inst2.size()) { std::cout<<"the size of the vectors is not the same\n"; return 0; } size_t n=inst1.s
TSS: Total Sum of Squares(总离差平方和) --- 因变量的方差 RSS: Residual Sum of Squares (残差平方和) --- 由误差导致的真实值和估计值之间的偏差平方和(Sum Of Squares Due To Error) ESS: Explained Sum of Squares (回归平方和) --- 被模型解释的方差(Sum Of Squares Due To Regression) TSS=RSS+ESS R2: Coefficien