Example #1
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 #2
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);
   }
 }