저는 Instances 객체를 구축하고 Attributes를 추가 한 다음 Instance 객체의 형태로 데이터를 추가합니다.Weka core의 문제 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