예제 #1
0
  @Test
  public void testClone() {
    System.out.println("clone");
    for (boolean useCatFeatures : new boolean[] {true, false}) {
      RandomForest instance = new RandomForest();

      ClassificationDataSet t1 = FixedProblems.getSimpleKClassLinear(100, 3);
      ClassificationDataSet t2 = FixedProblems.getSimpleKClassLinear(100, 6);
      if (useCatFeatures) {
        t1.applyTransform(new NumericalToHistogram(t1));
        t2.applyTransform(new NumericalToHistogram(t2));
      }

      instance = instance.clone();

      instance.trainC(t1);

      RandomForest result = instance.clone();
      for (int i = 0; i < t1.getSampleSize(); i++)
        assertEquals(t1.getDataPointCategory(i), result.classify(t1.getDataPoint(i)).mostLikely());
      result.trainC(t2);

      for (int i = 0; i < t1.getSampleSize(); i++)
        assertEquals(
            t1.getDataPointCategory(i), instance.classify(t1.getDataPoint(i)).mostLikely());

      for (int i = 0; i < t2.getSampleSize(); i++)
        assertEquals(t2.getDataPointCategory(i), result.classify(t2.getDataPoint(i)).mostLikely());
    }
  }
예제 #2
0
  @Test
  public void testTrainC_ClassificationDataSetMissingFeat() {
    System.out.println("trainC");
    for (boolean useCatFeatures : new boolean[] {true, false}) {
      RandomForest instance = new RandomForest();

      ClassificationDataSet train = FixedProblems.getCircles(1000, 1.0, 10.0, 100.0);
      // RF may not get boundry perfect, so use noiseless for testing
      ClassificationDataSet test =
          FixedProblems.getCircles(1000, 0.0, new XORWOW(), 1.0, 10.0, 100.0);

      train.applyTransform(new InsertMissingValuesTransform(0.1));
      test.applyTransform(new InsertMissingValuesTransform(0.01));

      ClassificationModelEvaluation cme = new ClassificationModelEvaluation(instance, train);
      if (useCatFeatures)
        cme.setDataTransformProcess(
            new DataTransformProcess(
                new NumericalToHistogram.NumericalToHistogramTransformFactory()));
      cme.evaluateTestSet(test);

      if (useCatFeatures) // hard to get right with only 2 features like this
      assertTrue(cme.getErrorRate() <= 0.17);
      else assertTrue(cme.getErrorRate() <= 0.1);
    }
  }
예제 #3
0
  @Test
  public void testTrainC_ClassificationDataSet_ExecutorService() {
    System.out.println("trainC");

    for (boolean useCatFeatures : new boolean[] {true, false}) {
      RandomForest instance = new RandomForest();

      ExecutorService ex = Executors.newFixedThreadPool(SystemInfo.LogicalCores);

      ClassificationDataSet train = FixedProblems.getCircles(1000, 1.0, 10.0, 100.0);
      // RF may not get boundry perfect, so use noiseless for testing
      ClassificationDataSet test =
          FixedProblems.getCircles(100, 0.0, new XORWOW(), 1.0, 10.0, 100.0);

      ClassificationModelEvaluation cme = new ClassificationModelEvaluation(instance, train, ex);
      if (useCatFeatures)
        cme.setDataTransformProcess(
            new DataTransformProcess(
                new NumericalToHistogram.NumericalToHistogramTransformFactory()));
      cme.evaluateTestSet(test);

      assertTrue(cme.getErrorRate() <= 0.001);

      ex.shutdownNow();
    }
  }
예제 #4
0
  @Test
  public void testTrainC_ClassificationDataSet() {
    System.out.println("trainC");
    for (boolean conc : new boolean[] {true, false}) {
      OneVSOne instance = new OneVSOne(new DCDs(), conc);

      ClassificationDataSet train = FixedProblems.getSimpleKClassLinear(1000, 7);
      ClassificationDataSet test = FixedProblems.getSimpleKClassLinear(100, 7);

      ClassificationModelEvaluation cme = new ClassificationModelEvaluation(instance, train);
      cme.evaluateTestSet(test);

      assertTrue(cme.getErrorRate() <= 0.001);
    }
  }
예제 #5
0
  @Test
  public void testTrainC_ClassificationDataSet_ExecutorService() {
    System.out.println("trainC");
    for (boolean conc : new boolean[] {true, false}) {
      OneVSOne instance = new OneVSOne(new DCDs(), conc);

      ClassificationDataSet train = FixedProblems.getSimpleKClassLinear(1000, 7);
      ClassificationDataSet test = FixedProblems.getSimpleKClassLinear(100, 7);

      ExecutorService ex = Executors.newFixedThreadPool(SystemInfo.LogicalCores);

      ClassificationModelEvaluation cme = new ClassificationModelEvaluation(instance, train, ex);
      cme.evaluateTestSet(test);

      assertTrue(cme.getErrorRate() <= 0.001);
    }
  }
예제 #6
0
  @Test
  public void testTrainC_RegressionDataSet() {
    System.out.println("train");
    for (boolean useCatFeatures : new boolean[] {true, false}) {
      RandomForest instance = new RandomForest();

      RegressionDataSet train = FixedProblems.getLinearRegression(1000, new XORWOW(), coefs);
      RegressionDataSet test = FixedProblems.getLinearRegression(100, new XORWOW(), coefs);

      RegressionModelEvaluation rme = new RegressionModelEvaluation(instance, train);
      if (useCatFeatures)
        rme.setDataTransformProcess(
            new DataTransformProcess(
                new NumericalToHistogram.NumericalToHistogramTransformFactory()));
      rme.evaluateTestSet(test);

      assertTrue(rme.getMeanError() <= test.getTargetValues().mean() * 2.5);
    }
  }
예제 #7
0
  @Test
  public void testClone() {
    System.out.println("clone");

    ClassificationDataSet t1 = FixedProblems.getSimpleKClassLinear(1000, 7);
    ClassificationDataSet t2 = FixedProblems.getSimpleKClassLinear(1000, 9);

    OneVSOne instance = new OneVSOne(new DCDs());

    instance = instance.clone();

    instance.trainC(t1);

    OneVSOne result = instance.clone();
    for (int i = 0; i < t1.getSampleSize(); i++)
      assertEquals(t1.getDataPointCategory(i), result.classify(t1.getDataPoint(i)).mostLikely());
    result.trainC(t2);

    for (int i = 0; i < t1.getSampleSize(); i++)
      assertEquals(t1.getDataPointCategory(i), instance.classify(t1.getDataPoint(i)).mostLikely());

    for (int i = 0; i < t2.getSampleSize(); i++)
      assertEquals(t2.getDataPointCategory(i), result.classify(t2.getDataPoint(i)).mostLikely());
  }