我正在使用apache commons-math庫來計算迴歸參數。如圖2和圖3所示,將2d陣列分配給單個陣列。當我使用相同的代碼,2D數組如何分配給1D數組?
我得到錯誤:
"Type mismatch error:cannot convert from double [][] to double []" in 3rd line but not for 2nd line.
OLSMultipleLinearRegression regression = new OLSMultipleLinearRegression();
double[] y = new double[]{11.0, 12.0, 13.0, 14.0, 15.0, 16.0};
double[] x = new double[6][];
x[0] = new double[]{0, 0, 0, 0, 0};
x[1] = new double[]{2.0, 0, 0, 0, 0};
x[2] = new double[]{0, 3.0, 0, 0, 0};
x[3] = new double[]{0, 0, 4.0, 0, 0};
x[4] = new double[]{0, 0, 0, 5.0, 0};
x[5] = new double[]{0, 0, 0, 0, 6.0};
regression.newSample(y, x);
爲什麼發生這種情況?以及這是如何工作的?
More details on OLS regression are given here
請不要在下次發佈代碼圖片時。 – Maroun
謝謝。我會記住這一點。 – Ranjeet