@Test public void evaluate() throws Exception { TrainingParameters params = new TrainingParameters(); params.put(TrainingParameters.ITERATIONS_PARAM, 100); params.put(TrainingParameters.CUTOFF_PARAM, 5); params.put("PrintMessages", false); final AtomicInteger correctCount = new AtomicInteger(); final AtomicInteger incorrectCount = new AtomicInteger(); LanguageDetectorCrossValidator cv = new LanguageDetectorCrossValidator(params, new LanguageDetectorFactory(), new LanguageDetectorEvaluationMonitor() { @Override public void correctlyClassified(LanguageSample reference, LanguageSample prediction) { correctCount.incrementAndGet(); } @Override public void missclassified(LanguageSample reference, LanguageSample prediction) { incorrectCount.incrementAndGet(); } }); LanguageDetectorSampleStream sampleStream = LanguageDetectorMETest.createSampleStream(); cv.evaluate(sampleStream, 2); Assert.assertEquals(99, cv.getDocumentCount()); Assert.assertEquals(0.98989898989899, cv.getDocumentAccuracy(), 0.01); }
public void evaluate(ObjectStream<LanguageSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<LanguageSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<LanguageSample> trainingSampleStream = partitioner.next(); LanguageDetectorModel model = LanguageDetectorME.train( trainingSampleStream, params, factory); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator( new LanguageDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); documentAccuracy.add(evaluator.getAccuracy(), evaluator.getDocumentCount()); } }
LanguageDetectorCrossValidator { public void evaluate(ObjectStream<LanguageSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<LanguageSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<LanguageSample> trainingSampleStream = partitioner.next(); LanguageDetectorModel model = LanguageDetectorME.train( trainingSampleStream, params, factory); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator( new LanguageDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); documentAccuracy.add(evaluator.getAccuracy(), evaluator.getDocumentCount()); } } }
LanguageDetectorCrossValidator { public void evaluate(ObjectStream<LanguageSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<LanguageSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<LanguageSample> trainingSampleStream = partitioner.next(); LanguageDetectorModel model = LanguageDetectorME.train( trainingSampleStream, params, factory); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator( new LanguageDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); documentAccuracy.add(evaluator.getAccuracy(), evaluator.getDocumentCount()); } } LanguageDetectorCrossValidator(TrainingParameters mlParams,
                                        LanguageDetectorFactory factory,
                                        LanguageDetectorEvaluationMonitor ... listeners); }
LanguageDetectorCrossValidator { public void evaluate(ObjectStream<LanguageSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<LanguageSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<LanguageSample> trainingSampleStream = partitioner.next(); LanguageDetectorModel model = LanguageDetectorME.train( trainingSampleStream, params, factory); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator( new LanguageDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); documentAccuracy.add(evaluator.getAccuracy(), evaluator.getDocumentCount()); } } LanguageDetectorCrossValidator(TrainingParameters mlParams,
                                        LanguageDetectorFactory factory,
                                        LanguageDetectorEvaluationMonitor ... listeners); void evaluate(ObjectStream<LanguageSample> samples, int nFolds); double getDocumentAccuracy(); long getDocumentCount(); }
LanguageDetectorCrossValidator { public void evaluate(ObjectStream<LanguageSample> samples, int nFolds) throws IOException { CrossValidationPartitioner<LanguageSample> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<LanguageSample> trainingSampleStream = partitioner.next(); LanguageDetectorModel model = LanguageDetectorME.train( trainingSampleStream, params, factory); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator( new LanguageDetectorME(model), listeners); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); documentAccuracy.add(evaluator.getAccuracy(), evaluator.getDocumentCount()); } } LanguageDetectorCrossValidator(TrainingParameters mlParams,
                                        LanguageDetectorFactory factory,
                                        LanguageDetectorEvaluationMonitor ... listeners); void evaluate(ObjectStream<LanguageSample> samples, int nFolds); double getDocumentAccuracy(); long getDocumentCount();  }