2010-11-17 186 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」

就是這樣,祝你好運!