Using Weka Java Code - How to convert CSV (without title bar) to ARFF format?

I am using the Weka Java library to read in a CSV file and convert it to an ARFF file .

The problem is that the CSV file does not have a header line , but only data. How to assign attribute names after entering CSV file? (all columns will be string data types)

Here is the code that I still have:

    CSVLoader loader = new CSVLoader();
    loader.setSource(new File(CSVFilePath));
    Instances data = loader.getDataSet();

    ArffSaver saver = new ArffSaver();
    saver.setInstances(data);
    saver.setFile(new File(outputFilePath));
    saver.writeBatch();

I tried to look at the Weka source code to figure it out, but I could not make heads or tails out of it: - (

+3
source share
3 answers

: .

CSVLoader , CSV - . , , , , .

, .

weka.

+5

-H, .

CSVLoader loader = new CSVLoader();
loader.setSource(new File(CSVFilePath));

String[] options = new String[1]; 
options[0] = "-H";
loader.setOptions(options);

Instances data = loader.getDataSet();

: http://weka.sourceforge.net/doc.dev/weka/core/converters/CSVLoader.html

+2

:

SELECT 'nameColumn1','nameColumn2'
UNION
SELECT idColumn1,idColumn2
FROM path
 INTO OUTFILE '/tmp/w.csv'
 FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
 LINES TERMINATED BY '\n';

nameColumn1 nameColumn2 - , csv.

+1

Source: https://habr.com/ru/post/1760423/


All Articles