2017-11-27 18 views
0

私はInstancesオブジェクトを構築し、Attributesを追加してから、インスタンスオブジェクトの形式でデータを追加します。Wekaコアの問題DenseInstance

これを書き出すと、toString()メソッドはすでにOutOfBoundsExceptionをスローしており、インスタンス内のデータを評価できません。データを出力しようとするとエラーが発生し、データオブジェクトのtoString()を評価できないことを示すように、例外がスローされていることがわかります。

エラーメッセージは、最初のデータ要素(StudentId)を使用してインデックスとして使用しているようです。なぜ私は混乱しています。

コード:

// Set up the attributes for the Weka data model 
ArrayList<Attribute> attributes = new ArrayList<>(); 
attributes.add(new Attribute("StudentIdentifier", true)); 
attributes.add(new Attribute("CourseGrade", true)); 
attributes.add(new Attribute("CourseIdentifier")); 
attributes.add(new Attribute("Term", true)); 
attributes.add(new Attribute("YearCourseTaken", true)); 

// Create the data model object - I'm not happy that capacity is required and fixed? But that's another issue 
Instances dataSet = new Instances("Records", attributes, 500); 
// Set the attribute that will be used for prediction purposes - that will be CourseIdentifier 
dataSet.setClassIndex(2); 

// Pull back all the records in this term range, create Weka Instance objects for each and add to the data set 
List<Record> records = recordsInTermRangeFindService.find(0, 10); 
int count = 0; 
for (Record r : records) { 
    Instance i = new DenseInstance(attributes.size()); 

    i.setValue(attributes.get(0), r.studentIdentifier); 
    i.setValue(attributes.get(1), r.courseGrade); 
    i.setValue(attributes.get(2), r.courseIdentifier); 
    i.setValue(attributes.get(3), r.term); 
    i.setValue(attributes.get(4), r.yearCourseTaken); 

    dataSet.add(i); 
} 

System.out.println(dataSet.size()); 
BufferedWriter writer = null; 
try { 
    writer = new BufferedWriter(new FileWriter("./test.arff")); 
    writer.write(dataSet.toString()); 
    writer.flush(); 
    writer.close(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

エラーメッセージ:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1010, Size: 0 

答えて

0

私はついにそれを考え出しました。私はコンストラクタの '真の'第2パラメータを持つ文字列に属性を設定していましたが、データベーステーブルから出てくる整数でした。私は、文字列に整数に変換するために私の行を変更するために必要な:

i.setValue(attributes.get(0), Integer.toString(r.studentIdentifier)); 

しかし、アプリオリアルゴリズムのようなものが文字列では動作しませんように私のための問題点の異なるセットを作成しました!私はWekaを学ぶことに続けています。

関連する問題