快速随机森林算法实现

use*_*165 0 java algorithm weka random-forest

我使用Weka lib和Random Forest实现了一个小的java应用程序.我已经训练了一些带有样本数据的分类器,并获得了大约85%的精确度.但是,当我使用快速随机森林(https://code.google.com/p/fast-random-forest/)时,它会开始抛出错误.

我已经实现了快速随机森林并使用当前的jar文件构建它.但是,当我们评估训练数据上的分类器时,它会不断出现以下错误:

 "The method evaluateModel(Classifier, Instances, Object...) 
  in the type Evaluation is not applicable for the arguments 
  (FastRandomForest, Instances) "
Run Code Online (Sandbox Code Playgroud)

对于这个当前代码:

    FastRandomForest rTree = new FastRandomForest();        
    rTree.buildClassifier(trainingData);

    showTree(rTree);

    System.out.println("records: " + trainingData.attribute(classIndex));
    System.out.println("number of instances: " + trainingData.numInstances());
    System.out.println(trainingData.instance(1));
    System.out.println("target: " + trainingData.classAttribute());
    //System.out.println(rTree.classifyInstance(trainingData.instance(1)));


    /* Evaluate the classifier on Training data */
    Evaluation eTest = new Evaluation(trainingData);
    eTest.evaluateModel(rTree, trainingData); 
    String strSummary = eTest.toSummaryString(); 
    System.out.println(strSummary);
Run Code Online (Sandbox Code Playgroud)

帮助赞赏!!

Jon*_*nny 5

问题是FastRandomForest不能分配给Classifier.你可以创建一个适配器,使FastRandomForest行为像一个Classifier.

public class FastRandomForestAdapter : Classifier {
  private FastRandomForest frf;
  public FastRandomForestAdpter(FastRandomForest frf) {
    this.frf = frf;
  }

  @override
  public void MethodA() {
    frf.Method1();
  }

  @override
  public ReturnType MethodB(object arg) {
    return frf.Method2(Transform(arg));
  }

  private Transform(object a) {
    ...
  }
}
Run Code Online (Sandbox Code Playgroud)