相关系数计算
public static double calCorrelation(Integer[] array1,Integer[] array2){double argXYSum = 0;
double argXSum = 0;
double argYSum = 0;
double argXSquSum = 0;
double argYSquSum = 0;
long n = 0;
for(int i=0; i<array1.length&&i<array2.length; i++){
n++;
argXYSum+=array1*array2;
argXSum+=array1;
argYSum+=array2;
argXSquSum+=Math.pow(array1,2);
argYSquSum+=Math.pow(array2,2);
}
double correlation = (n*argXYSum-argXSum*argYSum)/(Math.sqrt(n*argXSquSum-Math.pow(argXSum,2))*Math.sqrt(n*argYSquSum-Math.pow(argYSum,2)));
return correlation;
}
这就是所谓的协方差吧
页:
[1]