爲了計算兩個陣列之間的pearsons係數我使用下面的:如何計算相關如果一個值是0
double[] arr1 = new double[4];
arr1[0] = 1;
arr1[1] = 1;
arr1[2] = 1;
arr1[3] = 1;
double[] arr2 = new double[4];
arr2[0] = 1;
arr2[1] = 1;
arr2[2] = 1;
arr2[3] = 1;
PearsonsCorrelation pc = new PearsonsCorrelation();
println("Correlation is "+pc.correlation(arr1, arr2));
對於輸出I接收:相關是NaN
的PearsonsCorrelation class包含在apache commons API中:http://commons.apache.org/proper/commons-math/userguide/stat.html
每個數組中的值基於用戶在其數據集中包含一個單詞。上面的數組應該完全相關?
這個問題是關係到How to set a value's for calculating Eucludeian distance and correlation