Example #1
0
 private static void writeArffHeader(DataSet dataSet, String outputFile) {
   MLAssignmentUtils.writeToFile(outputFile, "@Relation RCATransformed\n", false);
   Vector vector = dataSet.get(0).getData();
   for (int i = 0; i < vector.size(); i++) {
     MLAssignmentUtils.writeToFile(outputFile, "@attribute attr" + (i + 1) + " numeric\n", true);
   }
   MLAssignmentUtils.writeToFile(outputFile, "@data\n", true);
 }
Example #2
0
 private static String getLabel(Instance label, List<String> labels) {
   Vector vector = label.getData();
   for (int i = 0; i < vector.size(); i++) {
     if (vector.get(i) == 1) {
       return labels.get(i);
     }
   }
   throw new RuntimeException("No label with value found");
 }
Example #3
0
 private static void saveAsArff(DataSet dataSet, String outputFile, List<String> labels) {
   writeArffHeader(dataSet, outputFile);
   Instance[] instances = dataSet.getInstances();
   for (Instance instance : instances) {
     Vector vector = instance.getData();
     for (int i = 0; i < vector.size(); i++) {
       MLAssignmentUtils.writeToFile(outputFile, String.valueOf(vector.get(i)) + ",", true);
     }
     MLAssignmentUtils.writeToFile(outputFile, getLabel(instance.getLabel(), labels) + "\n", true);
   }
 }