ConfusionMatrix { public Matrix getMatrix() { int length = confusionMatrix.length; Matrix m = new DenseMatrix(length, length); for (int r = 0; r < length; r++) { for (int c = 0; c < length; c++) { m.set(r, c, confusionMatrix[r][c]); } } Map<String,Integer> labels = Maps.newHashMap(); for (Map.Entry<String, Integer> entry : labelMap.entrySet()) { labels.put(entry.getKey(), entry.getValue()); } m.setRowLabelBindings(labels); m.setColumnLabelBindings(labels); return m; } ConfusionMatrix(Collection<String> labels, String defaultLabel);  ConfusionMatrix(Matrix m); int[][] getConfusionMatrix(); Collection<String> getLabels(); double getAccuracy(String label); double getAccuracy(); double getReliability(); double getKappa(); RunningAverageAndStdDev getNormalizedStats(); int getCorrect(String label); int getTotal(String label); void addInstance(String correctLabel, ClassifierResult classifiedResult); void addInstance(String correctLabel, String classifiedLabel); int getCount(String correctLabel, String classifiedLabel); void putCount(String correctLabel, String classifiedLabel, int count); String getDefaultLabel(); void incrementCount(String correctLabel, String classifiedLabel, int count); void incrementCount(String correctLabel, String classifiedLabel); ConfusionMatrix merge(ConfusionMatrix b); Matrix getMatrix(); void setMatrix(Matrix m); @Override String toString();  }
@Test public void testGetMatrix() { ConfusionMatrix cm = fillCM(VALUES, LABELS, DEFAULT_LABEL); Matrix m = cm.getMatrix(); Map<String, Integer> rowLabels = m.getRowLabelBindings(); assertEquals(cm.getLabels().size(), m.numCols()); assertTrue(rowLabels.keySet().contains(LABELS[0])); assertTrue(rowLabels.keySet().contains(LABELS[1])); assertTrue(rowLabels.keySet().contains(DEFAULT_LABEL)); assertEquals(2, cm.getCorrect(LABELS[0])); assertEquals(20, cm.getCorrect(LABELS[1])); assertEquals(0, cm.getCorrect(DEFAULT_LABEL)); }