CSVDatasetAdapter implements IDatasetDeserializer<ILabeledDataset<ILabeledInstance>> { public static void writeDataset(final File arffOutputFile, final ILabeledDataset<? extends ILabeledInstance> data) throws IOException { try (BufferedWriter bw = new BufferedWriter(new FileWriter(arffOutputFile))) { bw.write(data.getInstanceSchema().getAttributeList().stream().map(x -> "\"" + x.getName() + "\"").collect(Collectors.joining(","))); bw.write(","); bw.write("\"" + data.getLabelAttribute().getName() + "\""); bw.write("\n"); for (ILabeledInstance instance : data) { bw.write(IntStream.range(0, instance.getNumAttributes()).mapToObj(x -> serializeAttributeValue(data.getAttribute(x), instance.getAttributeValue(x))).collect(Collectors.joining(","))); bw.write(","); bw.write(serializeAttributeValue(data.getInstanceSchema().getLabelAttribute(), instance.getLabel())); bw.write("\n"); } } } CSVDatasetAdapter(); @Override ILabeledDataset<ILabeledInstance> deserializeDataset(final IDatasetDescriptor datasetDescription); static ILabeledDataset<ILabeledInstance> readDataset(final File csvInputFile); static void writeDataset(final File arffOutputFile, final ILabeledDataset<? extends ILabeledInstance> data);  }
@Test public void testWriteDataset() throws DatasetDeserializationFailedException, IOException { ILabeledDataset<ILabeledInstance> dataset = OpenMLDatasetReader.deserializeDataset(31); File f = new File("test.csv"); CSVDatasetAdapter.writeDataset(f, dataset); assertTrue(f.exists()); }