'how to convert .csv into .arff file though weka api and add values to last column of csv file

i want to convert a csv file into arff file but i am creating my csv file through a string and it does not have a class label (0,1) , i want to create a arff file from this csv file for that string and add a last column named (Outcome) which will be nominal having 0,1

I have created a csv file in eclipse from a string and added the values in each column accordingly and add a column named Outcome and give it ? as a value i don't know how to add 0 or 1 in this column or should i even add 0 or 1 in this column because i am new to ML prediction following is the code

 String data = "Pregnancies|Glucose|BloodPressure|SkinThickness|Insulin|BMI|DiabetesPedigreeFunction|Age|Outcome";
                          String csvh = data.replace("|", ",");
                        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("D:\\\\nust noor\\\\sda\\\\New folder\\\\MyCSV.csv")));
                        out.println(csvh);  
                      List<String> result = new ArrayList<>();
                        BufferedReader br = null;
                        try {
    br = new BufferedReader(new FileReader("C:\\\\runtime-EclipseXtext\\\\predict.prescription.models\\\\src-gen\\\\damninstances\\\\damninstances"));
                            String line;                            
                            while ((line = br.readLine()) != null) {
                                 String csv = line.replace(" ", ","); 
                                    String[] digits = csv.split(","); 
                                    for (int i = 0; i < digits.length; i=i+8) { 
                                        int k=digits.length-1; 
                                        if(i < k){   
                                            for (int j = i; j <= i+8; j++) {
                                                if(j != i){  
                                                    System.out.println("inside loopjjj"+j + "iiii "+i);
                                                    result.add(digits[j]);
                                                    } 
                                            }
                                            result.add("?");
                                            String arraytostring  = result.toString(); 
                                            arraytostring = arraytostring.substring(1, arraytostring.length() - 1);
                                           out.println(arraytostring);
                                           System.out.println(arraytostring);
                                           result.removeAll(result);
                                            }  
                                    
                                    } 
                            }

                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            if (br != null) {
                                br.close();
                            }
                        }
                        out.close();

this is the code of converting a csv file into arff file

CSVLoader loader = new CSVLoader();
                loader.setSource(new File("D:\\\\nust noor\\\\sda\\\\New folder\\\\MyCSV.csv"));
                Instances dada=loader.getDataSet();
                     ArffSaver saver3 = new ArffSaver();
             saver3.setInstances(dada);
     saver3.setFile(new File("D:\\nust noor\\sda\\New folder\\diabetesruntime.arff"));
     saver3.writeBatch();

i am getting arff file like this

@relation MyCSV

@attribute Pregnancies numeric
@attribute Glucose numeric
@attribute BloodPressure numeric
@attribute SkinThickness numeric
@attribute Insulin numeric
@attribute BMI numeric
@attribute DiabetesPedigreeFunction numeric
@attribute Age numeric
@attribute Outcome {' ?'}

@data
2,138,62,35,0,33,0,47,' ?'
0,145,0,0,0,41,1,31,' ?'
8,17,100,7,46,39,1,85,' ?'
2,16,120,2,200,60,1,20,' ?'

but i want a arff file like this

@RELATION MyCSV

@ATTRIBUTE attribute_0 {Pregnancies,0,2,8}
@ATTRIBUTE attribute_1 {Glucose,16,17,138,145}
@ATTRIBUTE attribute_2 {BloodPressure,0,62,100,120}
@ATTRIBUTE attribute_3 {SkinThickness,0,2,7,35}
@ATTRIBUTE attribute_4 {Insulin,0,46,200}
@ATTRIBUTE attribute_5 {BMI,33,39,41,60}
@ATTRIBUTE attribute_6 {DiabetesPedigreeFunction,0,1}
@ATTRIBUTE attribute_7 {Age,20,31,47,85}
@ATTRIBUTE attribute_8 {Outcome,0,1}

@DATA
Pregnancies,Glucose,BloodPressure,SkinThickness,Insulin,BMI,DiabetesPedigreeFunction,Age,Outcome
2, 138, 62, 35, 0, 33, 0, 47, ?
0, 145, 0, 0, 0, 41, 1, 31, 0 ?
8, 17, 100, 7, 46, 39, 1, 85, ?
2, 16, 120, 2, 200, 60, 1, 20, ?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source