【问题标题】:Fast Random Forest Algorithm Implementation快速随机森林算法实现
【发布时间】:2014-10-26 20:14:59
【问题描述】:

我已经使用带有随机森林的 Weka lib 实现了一个小型 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) "

对于当前代码:

    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);

帮助感激!

【问题讨论】:

  • FastRandomForest 是实现还是继承Classifier?消息说“我需要Classifier,但你给了我FastRandomForest”。
  • Jonny,不,它不会在 FastRandomForest 中扩展或实现分类器。这可能就是它造成它的原因。

标签: java algorithm weka random-forest


【解决方案1】:

问题是FastRandomForest 不能分配给Classifier。您可以创建一个adapter 以使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) {
    ...
  }
}

【讨论】:

    猜你喜欢
    • 2015-02-12
    • 2013-06-26
    • 2016-07-05
    • 2020-03-14
    • 2021-06-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    相关资源
    最近更新 更多