コード例 #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
ファイル: OneVSOneTest.java プロジェクト: hhyifeng/algorithm
  @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);
    }
  }
コード例 #3
0
ファイル: OneVSOneTest.java プロジェクト: hhyifeng/algorithm
  @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);
    }
  }
コード例 #4
0
ファイル: OneVSOneTest.java プロジェクト: hhyifeng/algorithm
  @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());
  }