我使用Weka lib和Random Forest实现了一个小的java应用程序。我已经训练了一些带有样本数据的分类器,并获得了大约85%的精确度。但是,当我使用快速随机森林(https://code.google.com/p/fast-random-forest/)时,它开始抛出错误。
我已经实现了快速随机森林并使用当前的jar文件构建它。但是,当我们在Training Data上评估分类器时,它会不断出现以下错误:
"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);
帮助赞赏!!
答案 0 :(得分: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) {
...
}
}