@Test public void testNaiveBayes2() throws IOException { testDataIndexer.index(NaiveBayesCorrectnessTest.createTrainingStream()); NaiveBayesModel model1 = (NaiveBayesModel) new NaiveBayesTrainer().trainModel(testDataIndexer); NaiveBayesModel model2 = persistedModel(model1); String label = "sports"; String[] context = {"bow=manchester", "bow=united"}; Event event = new Event(label, context); testModelOutcome(model1, model2, event); }
protected static void testModelOutcome(NaiveBayesModel model1, NaiveBayesModel model2, Event event) { String[] labels1 = extractLabels(model1); String[] labels2 = extractLabels(model2); Assert.assertArrayEquals(labels1, labels2); double[] outcomes1 = model1.eval(event.getContext()); double[] outcomes2 = model2.eval(event.getContext()); Assert.assertArrayEquals(outcomes1, outcomes2, 0.000000000001); }
@Test public void testNaiveBayes1() throws IOException { testDataIndexer.index(NaiveBayesCorrectnessTest.createTrainingStream()); NaiveBayesModel model1 = (NaiveBayesModel) new NaiveBayesTrainer().trainModel(testDataIndexer); NaiveBayesModel model2 = persistedModel(model1); String label = "politics"; String[] context = {"bow=united", "bow=nations"}; Event event = new Event(label, context); testModelOutcome(model1, model2, event); }
@Test public void testNaiveBayes3() throws IOException { testDataIndexer.index(NaiveBayesCorrectnessTest.createTrainingStream()); NaiveBayesModel model1 = (NaiveBayesModel) new NaiveBayesTrainer().trainModel(testDataIndexer); NaiveBayesModel model2 = persistedModel(model1); String label = "politics"; String[] context = {"bow=united"}; Event event = new Event(label, context); testModelOutcome(model1, model2, event); }
@Test public void testNaiveBayes4() throws IOException { testDataIndexer.index(NaiveBayesCorrectnessTest.createTrainingStream()); NaiveBayesModel model1 = (NaiveBayesModel) new NaiveBayesTrainer().trainModel(testDataIndexer); NaiveBayesModel model2 = persistedModel(model1); String label = "politics"; String[] context = {}; Event event = new Event(label, context); testModelOutcome(model1, model2, event); }