public static ConfusionMatrix of(int[] truth, int[] prediction) {
        if (truth.length != prediction.length) {
             throw new IllegalArgumentException(String.format("The vector sizes don't match: %d != %d.", truth.length, prediction.length));
        }

        Set<Integer> y = new HashSet<>();

        // Sometimes, small test data doesn't have all the classes.
        for (int i = 0; i < truth.length; i++) {
            y.add(truth[i]);
            y.add(prediction[i]);
        }

        int k = 0;
        for (int c : y) {
            if (k < c) k = c;
        }

        int[][] matrix = new int[k+1][k+1];
        for (int i = 0; i < truth.length; i++) {
            matrix[truth[i]][prediction[i]] += 1;
        }

        return new ConfusionMatrix(matrix);
    }
@Test
    public void test() {
        int[] truth = {0,1,2,3,4,5,0,1,2,3,4,5};
        int[] prediction = {0,1,2,4,5,2,1,2,4,5,4,1};

        ConfusionMatrix confusion = ConfusionMatrix.of(truth, prediction);
        System.out.println(confusion);

        int[][] matrix = confusion.matrix;
        int[] expected = {1,1,1,0,1,0};

        for(int i = 0; i < expected.length; i++){
            //main diagonal test
            assertEquals(matrix[i][i], expected[i]);
            //class 3 not predicted test
            assertEquals(matrix[i][3], 0);
        }
    }