LinearRegression implements EstimatableModel<double[], double[]> { public LinearRegression() { } LinearRegression(); @Override boolean estimate(List<? extends IndependentPair<double[], double[]>> data); void estimate(double[][] yd, double[][] xd); void estimate(Matrix y, Matrix x); @Override double[] predict(double[] data); Matrix predict(Matrix x); @Override int numItemsToEstimate(); @Override LinearRegression clone(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testLinearRegression() throws Exception { final double[][] xt = new double[][] { new double[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } }; final double m = 2; final double c = -2; final double[][] perfectyt = new double[1][xt[0].length]; for (int i = 0; i < perfectyt[0].length; i++) { perfectyt[0][i] = xt[0][i] * m + c; } final Matrix x = new Matrix(xt).transpose(); final Matrix perfecty = new Matrix(perfectyt).transpose(); final Matrix noise = new Matrix(RandomData.getRandomDoubleArray(perfecty.getRowDimension(), 1, -1, 1, 1)); final Matrix y = perfecty.plus(noise); final List<IndependentPair<double[], double[]>> ipairs = aspairs(x, y); final LinearRegression lr = new LinearRegression(); lr.estimate(y, x); final LinearRegression lr2 = new LinearRegression(); lr2.estimate(ipairs); assertTrue(lr.equals(lr2)); }