22

I've been trying to get this dataset http://archive.ics.uci.edu/ml/datasets/Communities+and+Crime+Unnormalized into Weka and no luck at all. I converted it to CSV and then loaded it into Weka and then tried to convert it to ARFF but still giving me the error "attribute names are not unique".

Also, do I have to spread the training dataset from testing dataset or keep them together?

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
LumberJack
  • 231
  • 1
  • 2
  • 3

9 Answers9

45

You can also use the ArffViewer (Tools -> ArffViewer or Ctrl+A). Then open your CSV file.

Next go to File -> Save as... and select Arff data files (should be selected by default).

Note that your fields must be separated with a comma and not a semicolon.

EsTeGe
  • 2,975
  • 5
  • 28
  • 42
15

There are some converters implemented in WEKA. Here are the API pages related to this topic: http://weka.sourceforge.net/doc.stable/weka/core/converters/package-summary.html

For example here is how to convert from CSV to ARFF:

java -cp /path/to/weka.jar weka.core.converters.CSVLoader filename.csv > filename.arff
cdated
  • 1,753
  • 1
  • 14
  • 24
arutaku
  • 5,937
  • 1
  • 24
  • 38
  • 1
    Just a comment for someone dumb like me - Above command is to be run after going to the directory where weka is installed i.e. where you can see `weka/core/converters/CSVLoader` as a directory structure. – user13107 Apr 25 '13 at 08:10
  • 1
    You can also do `java -cp /path/to/weka.jar weka.core.converters.CSVLoader filename.csv > filename.arff` – Phani Jun 24 '14 at 22:33
  • i get this error 'Error: Could not find or load main class weka.core.converters.CSVLoader' how to overcome this? – NIMISHAN Jan 31 '16 at 15:09
  • Make sure that you included the weka.jar in your classpath (using "-cp ") as in code line in the answer. Also, make sure that your JAR file contains the CSVLoader class in it! A JAR file is just a zip file, so double click on it and explore the path "weka/core/converters/". You should find there a CSVLoader.class file. – arutaku Feb 01 '16 at 10:27
5

Upload your .CSV format file to this. From that your .CSV format will be converted to WEKA .arff format. Once it is done fetch .arff file to Weka tool. Now you can proceed with your data analyzing.

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51
2

You need header fields in the csv. You need to add attr0,attr1,...,labels in the csv file in the first line.

1

I did not get any problem. Okay, do the following. In the web page you specified,

  • copy the segment between ".arff header for weka: " and "Relevant Papers".
  • paste it on a .txt file
  • open the data file at this location
  • copy the instances and append that to your .txt file right after @data section
  • save the .txt file as .arff file

You are now good to go.

do i have to spreate the training dataset from testing dataset or leave them together?

It depends on your classification method. If you choose 10-fold CV, then leave them together. If you want to use the convention method, separate them. Again, it all depends on your methodology.

Rushdi Shams
  • 2,423
  • 19
  • 31
  • Why on earth someone will give this question a negative vote? Also, as it solves the problem, why on earth my answer got the negative vote? Peculiar! – Rushdi Shams May 03 '12 at 15:41
  • OP is asking for CSV to ARFF conversion. But you did not answer that part. Hence someone downvoted I think. – user13107 Apr 25 '13 at 08:04
1

To convert .csv to .arff file format to use in Weka. Note : .csv file should be proper, else it will not convert to .arff file. It should not contain any null value in columns. Download the weka core jar. In Eclipse -->Configure Build path, add the weka core jar and write the below line of code and execute the code:

CSVToArff.java

import weka.core.Instances;
import weka.core.converters.ArffSaver;
import weka.core.converters.CSVLoader;

import java.io.File;

public class CSVToArff {

   public static void main(String[] args) throws Exception {


    // load CSV
    CSVLoader loader = new CSVLoader();
    loader.setSource(new File("Provide the input file location (.csv) "));
    Instances data = loader.getDataSet();

    // save ARFF
    ArffSaver saver = new ArffSaver();
    saver.setInstances(data);
    saver.setFile(new File("Provide the output file location (.arff) ");
    saver.writeBatch();
    // .arff file will be created in the output location
  }
}
0

Maybe this online CSV to ARFF converter can be useful?

http://slavnik.fe.uni-lj.si/markot/csv2arff/csv2arff.php

markotka
  • 86
  • 3
  • I used the above link, but my values didn't separated . that mean my 8227 lines of file came out with three lines, 1. header, 2. Attributes, 3. values. How to divide them row by row? – NIMISHAN Jan 31 '16 at 15:13
0

In weka using Simple CLI, we can convert .csv file to a .arff file easily.

Simply you have to navigate to Simple CLI -> Give the below command in the text field provided(first provide the .csv file name and then a name for the .arff you wants to convert)

java weka.core.converters.CSVLoader D:\L4S1\DataMining-Lab-Assignment-02\filename.csv > D:\L4S1\DataMining-Lab-Assignment-02\filename.arff

The below image shows the Simple CLI window

enter image description here

Niroshan Ratnayake
  • 3,433
  • 3
  • 20
  • 18
-1

it works

for example:- C:\Users\User\Desktop>java -cp "e:\data\weka-3-6-10\weka.jar;." weka.core.converters.CSVLoader data1.csv >> data1.arff 1.before conversion check that csv in excel as that any of the cells should not be improper 2.check that attributes are in proper

for plain csv - u must add header row even as x,y,z,... according to need