2010-11-17 180 views
0

我想运行一个执行Weka命令的Java程序。 我运行的程序是http://weka.wikispaces.com/Use+WEKA+in+your+Java+code,在增量分类器下,“一个工作示例是IncrementalClassifier.java”。无法运行执行weka命令的java程序

这是我的代码,我改变了ARFF的地址:

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) 

如何进行:

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

,我得到的是错误?

由于

回答

1

即文件(iris.2.arff)似乎有硬编码到源,如图here。我猜想这个文件随分发而来,但不在正确的位置。或者你可能调用了错误的方法。

+0

感谢您的回复。我不知道如何根据您的反馈采取行动。 – user511440 2010-11-18 00:18:06

+0

首先,更新您的帖子以包含整个堆栈跟踪,并指出源中的哪一行引发异常。 – 2010-11-18 00:34:15

+0

我得到的错误是:1.项目'CN170'缺少所需的库:'C:\ Program Files \ Weka-3-4 \ weka.jar'(资源:CN170,位置:构建路径),2。在解决构建路径错误之前无法构建项目(资源:CN170,位置:未知),3.未处理的异常类型IOException(资源:simpleprog.java,位置:line18)。 – user511440 2010-11-20 01:53:22

0

,这是因为你在你的java应用程序配置运行错误的类,你必须做的是:

右键单击项目:运行方式:运行配置:在域“主类”选择你的班级“IncrementalClassifier”

就是这样,祝你好运!