Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.util.Scanner;
  4.  
  5. import weka.core.Instances;
  6. import weka.core.converters.ArffSaver;
  7. import weka.core.converters.CSVLoader;
  8.  
  9. public class Coursework {
  10.  
  11.     public static void main(String[] args) throws FileNotFoundException {
  12.         //Convert a CSV file to ARFF format
  13.        
  14.         //load the csv file
  15.         try {
  16.             CSVLoader loader = new CSVLoader();
  17.             loader.setSource(new File("./new.csv"));
  18.             Instances data = loader.getDataSet();
  19.         //save an arff file
  20.             ArffSaver saver = new ArffSaver();
  21.             saver.setInstances(data);
  22.             saver.setFile(new File("./new.arff"));
  23.             saver.setDestination(new File("./new.arff"));
  24.             saver.writeBatch();
  25.         } catch (Exception e) {
  26.             e.printStackTrace();
  27.         }
  28. //      Scanner scanner = new Scanner(new File("./pre-processed.csv"));
  29. //      scanner.useDelimiter(",");
  30. //      while (scanner.hasNext()) {
  31. //          System.out.print(scanner.next() + "|");
  32. //      }
  33. //      scanner.close();
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement