gpt4 book ai didi

java - 无法运行执行weka命令的java程序

转载 作者:行者123 更新时间:2023-12-01 16:00:01 25 4
gpt4 key购买 nike

我正在尝试运行一个执行Weka命令的Java程序。我正在运行的程序位于 http://weka.wikispaces.com/Use+WEKA+in+your+Java+code ,在增量分类器下,“一个工作示例是 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)

如何进行?

谢谢

最佳答案

该文件 (iris.2.arff) 似乎已硬编码到源代码中,如 here 所示。我猜想这个文件是随发行版一起提供的,但位置不正确。或者您可能调用了错误的方法。

关于java - 无法运行执行weka命令的java程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4210062/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com