0

I have implemented a small java application using Weka lib with Random Forest. I have trained some classifiers with a sample data and getting a good accuracy of around 85%. However, when i used theFast Random Forest (https://code.google.com/p/fast-random-forest/) it starts throwing error(s).

I have implemented the Fast Random Forest and build it with current jar files. However, it keeps giving the following error when we evaluate the classifier on Training Data:

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

For this current code:

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

Help appreciated!!

2
  • Does FastRandomForest implement or inherit Classifier? The message is saying "I need a Classifier but you have given me a FastRandomForest". Commented Sep 2, 2014 at 14:17
  • Jonny, no it doesn't extend or implement Classifier in FastRandomForest. That's probably why it's causing it. Commented Sep 2, 2014 at 14:23

1 Answer 1

5

The problem is that FastRandomForest is not assignable to Classifier. You could create an adapter to make the FastRandomForest act like a 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) {
    ...
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.