private void updateInstanceAndPutInField(
     Instance instance, int correctClass, int predictedClassIndex) {
   Segment segment = toSegment(instance);
   String classAsString = instance.classAttribute().value(predictedClassIndex);
   int predictedLabelId = Integer.parseInt(classAsString);
   segment.setPredictedLabelDetail(labelMapReader.getSchema().get(predictedLabelId));
   putInField(segment, correctClass, predictedClassIndex);
 }
  private String getHeaders(List<Segment> segments) {
    if (segments.size() == 0) {
      return "";
    }
    Segment segment = segments.get(0);

    StringBuilder output = new StringBuilder();
    output.append("device_info_serial,");
    output.append("date_time,");
    output.append("lon,");
    output.append("lat,");
    output.append("alt,");
    output.append("class_id,");
    for (String feature : segment.getFeatureNames()) {
      output.append(feature + ",");
    }
    output.append("set\n");
    return output.toString();
  }
 private String getCsv(List<Segment> segments, String set) {
   StringBuilder output = new StringBuilder();
   for (Segment segment : segments) {
     output.append(segment.getDeviceId() + ",");
     output.append(segment.getTimeStamp().toString(Constants.DATE_TIME_PATTERN_ISO8601) + ",");
     output.append(segment.getLongitude() + ",");
     output.append(segment.getLatitude() + ",");
     output.append(segment.getAltitude() + ",");
     output.append(segment.getLabel() + ",");
     for (double feature : segment.getFeatures()) {
       output.append(feature + ",");
     }
     output.append(set + "\n");
   }
   return output.toString();
 }