0

I am trying to run a Java program that executes Weka commands. The program i am running is at http://weka.wikispaces.com/Use+WEKA+in+your+Java+code, under Incremental Classifiers, "A working example is IncrementalClassifier.java."

This is my code, and I changed the address of the arff:

import weka.core.Instance;
import weka.core.Instances;
import weka.core.converters.ArffLoader;
import weka.classifiers.bayes.NaiveBayesUpdateable;

import java.io.File;

/**
 * This example trains NaiveBayes incrementally on data obtained
 * from the ArffLoader.
 *
 * @author FracPete (fracpete at waikato dot ac dot nz)
 */
public class IncrementalClassifier {

  /**
   * Expects an ARFF file as first argument (class attribute is assumed
   * to be the last attribute).
   *
   * @param args        the commandline arguments
   * @throws Exception  if something goes wrong
   */
  public static void main(String[] args) throws Exception {
    // load data
    ArffLoader loader = new ArffLoader();
    loader.setFile(new File("C:\\Program Files\\Weka-3-6\\10random+5.arff"));
    Instances structure = loader.getStructure();
    structure.setClassIndex(structure.numAttributes() - 1);

    // train NaiveBayes
    NaiveBayesUpdateable nb = new NaiveBayesUpdateable();
    nb.buildClassifier(structure);
    Instance current;
    while ((current = loader.getNextInstance(structure)) != null)
      nb.updateClassifier(current);

    // output generated model
    System.out.println(nb);
  }
}

The error that I am getting is:

java.io.FileNotFoundException: \iris.2.arff (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.io.FileReader.<init>(Unknown Source)
    at weka.classifiers.bayes.net.ADNode.main(ADNode.java:270)

How to proceed?

Thanks

2 Answers 2

1

That file (iris.2.arff) seems to be hardcoded into the source, as shown here. I would guess that this file came with the distribution but is not in the correct location. Or possibly you are invoking the wrong method.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for replying. I don't know how to act on your feedback.
First, update your post to include the entire stack trace, and also indicate at which line in YOUR source the exception is thrown.
The errors that I get are: 1.Project 'CN170' is missing required library: 'C:\Program Files\Weka-3-4\weka.jar' (Resource: CN170, Location: Build path), 2. The project cannot be built until build path errors are resolved (Resource: CN170, Location: unknown), 3. Unhandled exception type IOException (Resource: simpleprog.java, location: line18).
That's very different from the original error, and indicates that weka.jar is not in your classpath.
0

this is because you're running the wrong class in your java application configuration, what you have to do is :

right click on project : Run As : Run configuration : In the field "Main Class" choose your class "IncrementalClassifier"

that's all, good luck !

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.