Reading a CSV file containing a dataset of 8×8 images I am trying to implement a machine learning algorithm (k-nn for example).  But before I attempt to do that I was hoping for some feedback on my current Main class, which essentially builds 8×8-pixel matrices into an array to be manipulated later. (See the data description and sample dataset.)

import java.util.*;
import java.io.*;

public class Main {

    static class Data {

        int[] dataSet;
        int classCode;

        public Data(int[] dataSet, int label) {
            this.dataSet = dataSet;
            this.classCode = label;
        }

        @Override
        public String toString() {
            return "Class Code: " + classCode + " DataSet:" + Arrays.toString(dataSet) + "\n";
        }

    }

    ArrayList&lt;Data&gt; dataSetList;
    int[][] dataArray = new int[2810][65];

    private void readFile(String csvFile) {
        int instances = 0;
        dataSetList = new ArrayList&lt;&gt;();
        try {
            Scanner scan = new Scanner(new BufferedReader(new FileReader(csvFile)));
            while (scan.hasNext()) {
                String line = scan.next();
                String[] extractedDataFromFile = line.split(",");
                for (int i = 0; i &lt; extractedDataFromFile.length; i++) {
                    dataArray[instances][i] = Integer.parseInt(extractedDataFromFile[i]);
                }
                dataSetList.add(new Data(dataArray[instances], dataArray[instances][extractedDataFromFile.length - 1]));
                instances++;
            }
            System.out.println(dataSetList.toString());
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage());
        }
    }

    public static void main(String[] args) {
        Main main = new Main();
        main.readFile("dataset1.csv");
    }

}


This is my first time experimenting with machine learning and any feedback on my current approach as well as an algorithm to look at beyond this would be hugely appreciated.
Outline

Data and Main aren't exactly helpful class names.  I suggest ImageMatrix and ImageMatrixDB.

In some sense, your code is incomplete, because it just prints the data that it read.  To make this code useful, you would have to offer a way to retrieve the data — and not just by directly accessing dataSetList and dataArray, which should have been private.  I suggest the an outline like this:

ImageMatrix.java

public class ImageMatrix {
    public ImageMatrix(int[] data, int classCode) {
        assert data.length == 64;
        …
    }

    public int[] getData() {
        …
    }

    public int getClassCode() {
        …
    }
}


ImageMatrixDB.java

public class ImageMatrixDB implements Iterable&lt;ImageMatrix&gt; {
    private List&lt;ImageMatrix&gt; list = new ArrayList&lt;&gt;;

    public static ImageMatrixDB load(File f) throws IOException {
        …
    }

    public Iterator&lt;ImageMatrix&gt; iterator() {
        return this.list.iterator();
    }
}


Why are you storing the same data twice, in both dataSetList and dataArray?  You should drop the dataArray, which relies on the magic number 2810.

The file parameter should be a File rather than a String, so as not to give the impression that you it accepts the contents of the file rather than the name of the file.

The parsing routine needs a way to report failure to its caller.  No, printing an error message doesn't count, as the caller would still proceed obliviously.

Implementation

Why are you using a Scanner?  The BufferedReader already has a readLine() method that does what you want.  Note that you fail to close the FileReader, BufferedReader, and the Scanner.

In the Data object, the dataSet array has 65 elements: the 64 data points and the class code.  The class code has no business being part of that array.

public static ImageMatrixDB load(File f) throws IOException {
    ImageMatrixDB result = new ImageMatrixDB();
    try (FileReader fr = new FileReader(f);
         BufferedReader br = new BufferedReader(fr)) {
        for (String line; null != (line = br.readLine()); ) {
            int lastComma = line.lastIndexOf(',');
            int classCode = Integer.parseInt(line.substring(1 + lastComma));
            int[] data = Arrays.stream(line.substring(0, lastComma).split(","))
                               .mapToInt(Integer::parseInt)
                               .toArray();
            result.list.add(new ImageMatrix(data, classCode));
        }
    }
    return result;
}