Reputation: 231
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?
Upvotes: 22
Views: 116734
Reputation: 3801
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
Upvotes: 0
Reputation: 11
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
}
}
Upvotes: 1
Reputation: 303
You need header fields in the csv. You need to add attr0,attr1,...,labels in the csv file in the first line.
Upvotes: 2
Reputation: 6087
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
Upvotes: 15
Reputation: 12757
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.
Upvotes: 5
Reputation: 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
Upvotes: -1
Reputation: 3055
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.
Upvotes: 46
Reputation: 86
Maybe this online CSV to ARFF converter can be useful?
http://slavnik.fe.uni-lj.si/markot/csv2arff/csv2arff.php
Upvotes: 0
Reputation: 2423
I did not get any problem. Okay, do the following. In the web page you specified,
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.
Upvotes: 1