コード例 #1
0
  @Test
  public void testRandomForest() {

    RandomForest forest = RandomForest.create(10).setNumRandomFeaturesToChoose(10);
    forest.train(mushroom.getFeatures(), mushroom.getOutcomes());

    EvaluationResult res =
        Evaluator.testClassifier(forest, mushroom.getFeatures(), mushroom.getOutcomes());

    assertEquals(1d, res.getAccuracy(), 0.1);
  }
コード例 #2
0
 @Test
 public void testSerialization() throws IOException {
   RandomForest forest = RandomForest.create(10).setNumRandomFeaturesToChoose(10);
   forest.train(mushroom.getFeatures(), mushroom.getOutcomes());
   EvaluationResult res =
       Evaluator.testClassifier(forest, mushroom.getFeatures(), mushroom.getOutcomes());
   assertEquals(1d, res.getAccuracy(), 0.1);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   RandomForest.serialize(forest, new DataOutputStream(baos));
   ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
   RandomForest deserialized = RandomForest.deserialize(new DataInputStream(bais));
   res = Evaluator.testClassifier(deserialized, mushroom.getFeatures(), mushroom.getOutcomes());
   assertEquals(1d, res.getAccuracy(), 0.1);
 }