Converting+CSV+to+ARFF

toc For converting CSV (comma separated value) files into ARFF files you need the following two [|converters]:
 * [|CSVLoader] for loading the CSV file into an [|Instances] object
 * [|ArffSaver] to save the [|Instances] as an ARFF file

In the following you'll find some example code to show you how to use the [|converters]. The class takes 2 arguments:
 * the //input// CSV file
 * the //output// ARFF file

Example code: code format="java" import weka.core.Instances; import weka.core.converters.ArffSaver; import weka.core.converters.CSVLoader;

import java.io.File;

public class CSV2Arff { /**  * takes 2 arguments: * - CSV input file * - ARFF output file */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.out.println("\nUsage: CSV2Arff  \n"); System.exit(1); }   // load CSV CSVLoader loader = new CSVLoader; loader.setSource(new File(args[0])); Instances data = loader.getDataSet;

// save ARFF ArffSaver saver = new ArffSaver; saver.setInstances(data); saver.setFile(new File(args[1])); saver.setDestination(new File(args[1])); saver.writeBatch; } } code
 * Note:** with versions of Weka later than 3.5.3 the call of is no longer necessary, it is automatically done in the  method.