私は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