我正在尝试运行一个执行 Weka 命令的 Java 程序。我正在运行的程序位于http://weka.wikispaces.com/Use+WEKA+in+your+Java+code的 Incremental Classifiers 下,“一个工作示例是 IncrementalClassifier.java”。
这是我的代码,我更改了 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);
}
}
我得到的错误是:
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)
如何进行?
谢谢