2014-09-02 159 views
0

我已经用随机森林实现了一个使用Weka库的小型Java应用程序。我已经用样本数据训练了一些分类器并获得了85%左右的精确度。但是,当我使用快速随机森林(https://code.google.com/p/fast-random-forest/)时,它开始抛出错误(s)。快速随机森林算法实现

我已经实现了快速随机森林并使用当前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); 

帮助表示赞赏!

+1

堆栈跟踪请 – StackFlowed 2014-09-02 14:16:51

+0

'FastRandomForest'实现或继承'Classifier'吗?该消息是说“我需要一个Classifier”,但你给了我一个'FastRandomForest'“。 – Jonny 2014-09-02 14:17:07

+0

Jonny,不,它没有在FastRandomForest中扩展或实现分类器。这可能是它造成它的原因。 – user2501165 2014-09-02 14:23:26

回答

5

问题是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) { 
    ... 
    } 
}