LinearRegressionModel implements IgniteModel<Vector, Double>, Exportable<LinearRegressionModel>, Serializable { @Override public Double predict(Vector input) { return input.dot(weights) + intercept; } LinearRegressionModel(Vector weights, double intercept); Vector getWeights(); double getIntercept(); @Override Double predict(Vector input); @Override void saveModel(Exporter<LinearRegressionModel, P> exporter, P path); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @Override String toString(boolean pretty);  }
@Test public void testPredict() { Vector weights = new DenseVector(new double[]{2.0, 3.0}); LinearRegressionModel mdl = new LinearRegressionModel(weights, 1.0); assertTrue(!mdl.toString().isEmpty()); assertTrue(!mdl.toString(true).isEmpty()); assertTrue(!mdl.toString(false).isEmpty()); Vector observation = new DenseVector(new double[]{1.0, 1.0}); TestUtils.assertEquals(1.0 + 2.0 * 1.0 + 3.0 * 1.0, mdl.predict(observation), PRECISION); observation = new DenseVector(new double[]{2.0, 1.0}); TestUtils.assertEquals(1.0 + 2.0 * 2.0 + 3.0 * 1.0, mdl.predict(observation), PRECISION); observation = new DenseVector(new double[]{1.0, 2.0}); TestUtils.assertEquals(1.0 + 2.0 * 1.0 + 3.0 * 2.0, mdl.predict(observation), PRECISION); observation = new DenseVector(new double[]{-2.0, 1.0}); TestUtils.assertEquals(1.0 - 2.0 * 2.0 + 3.0 * 1.0, mdl.predict(observation), PRECISION); observation = new DenseVector(new double[]{1.0, -2.0}); TestUtils.assertEquals(1.0 + 2.0 * 1.0 - 3.0 * 2.0, mdl.predict(observation), PRECISION); }
@Test(expected = CardinalityException.class) public void testPredictOnAnObservationWithWrongCardinality() { Vector weights = new DenseVector(new double[]{2.0, 3.0}); LinearRegressionModel mdl = new LinearRegressionModel(weights, 1.0); Vector observation = new DenseVector(new double[]{1.0}); mdl.predict(observation); }