Convert CSV to ARFF for weka - Java Machine Learning AI

Java examples for Machine Learning AI:weka

Description

Convert CSV to ARFF for weka

Demo Code


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class CSVtoARFF {

  public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    String csvFile = "/v2.csv";

    BufferedReader br = null;/*from w w  w.  j av a2  s .  com*/
    String line = "";
    String cvsSplitBy = ",";
    String date = "";
    String[] states = new String[] {};

    br = new BufferedReader(new FileReader(csvFile));
    int counter = 0;

    while ((line = br.readLine()) != null) {
      String[] var = line.split(cvsSplitBy);
      if (counter == 0) {
        states = var;
        counter++;
        continue;
      }
      date = var[0].toString();
      for (int i = 0; i < var.length; i++) {
        if (!states[i].equals("time")) {
          System.out.println(date + "," + states[i] + "," + var[i]);
        }
      }

    }

  }

}

Related Tutorials