GaussianNaiveBayesModel implements IgniteModel<Vector, Double>, Exportable<GaussianNaiveBayesModel>, Serializable { @Override public Double predict(Vector vector) { int k = classProbabilities.length; double maxProbability = .0; int max = 0; for (int i = 0; i < k; i++) { double p = classProbabilities[i]; for (int j = 0; j < vector.size(); j++) { double x = vector.get(j); double g = gauss(x, means[i][j], variances[i][j]); p *= g; } if (p > maxProbability) { max = i; maxProbability = p; } } return labels[max]; } GaussianNaiveBayesModel(double[][] means, double[][] variances,
        double[] classProbabilities, double[] labels, GaussianNaiveBayesSumsHolder sumsHolder); @Override void saveModel(Exporter<GaussianNaiveBayesModel, P> exporter, P path); @Override Double predict(Vector vector); double[][] getMeans(); double[][] getVariances(); double[] getClassProbabilities(); GaussianNaiveBayesSumsHolder getSumsHolder();  }
@Test public void testPredictWithTwoClasses() { double first = 1; double second = 2; double[][] means = new double[][] { {5.855, 176.25, 11.25}, {5.4175, 132.5, 7.5}, }; double[][] variances = new double[][] { {3.5033E-2, 1.2292E2, 9.1667E-1}, {9.7225E-2, 5.5833E2, 1.6667}, }; double[] probabilities = new double[] {.5, .5}; GaussianNaiveBayesModel mdl = new GaussianNaiveBayesModel(means, variances, probabilities, new double[] {first, second}, null); Vector observation = VectorUtils.of(6, 130, 8); Assert.assertEquals(second, mdl.predict(observation), 0.0001); }