通过计算得到相关性,两个数组必须长度一致。 /*计算平均数*/function ArrAvg(x) {var sum = x.reduce(function(a, b) {return a + b});return sum / (x.length);}/*计算方差*/function ArrVar(x) {var avg = ArrAvg(x);var re
/*计算平均数*/ function ArrAvg(x) { var sum = x.reduce(function(a, b) { return a + b }); return sum / (x.length); } /*计算方差*/ function ArrVar(x) { var avg = ArrAvg(x); var res = 0; for(let i = 0; i < x.length; i++) { res = res + Math.pow((x[i] - avg), 2) / (x.length); } return res; } /*计算协方差*/ function ArrCov(x, y) { var cov = 0; var xAvg = ArrAvg(x); var yAvg = ArrAvg(y); for(var i = 0; i < (x.length); i++) { cov = cov + (x[i] - xAvg) * (y[i] - yAvg); } return cov / (x.length); } /*计算相关性*/ function ArrPer(x, y) { return ArrCov(x, y) / (Math.sqrt(ArrVar(x) * ArrVar(y))); } 加密之后代码 eval(function(p,a,c,k,e,d){e=function(c){return(c 35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1;};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p;}('6 9(1){3 e=1.p(6(a,b){7 a+b});7 e/(1.5)}6 d(1){3 g=9(1);3 c=0;f(o i=0;i<1.5;i++){c=c+l.m((1[i]-g),2)/(1.5)}7 c}6 k(1,4){3 8=0;3 h=9(1);3 j=9(4);f(3 i=0;i<(1.5);i++){8=8+(1[i]-h)*(4[i]-j)}7 8/(1.5)}6 q(1,4){7 k(1,4)/(l.n(d(1)*d(4)))}',27,27,'|x||var|y|length|function|return|cov|ArrAvg|||res|ArrVar|sum|for|avg|xAvg||yAvg|ArrCov|Math|pow|sqrt|let|reduce|ArrPer'.split('|'),0,{}))