StringUtils.leftPad(decimalFormatter.format(normStats.getStandardDeviation()), 10)).append('\n'); returnString.append(StringUtils.rightPad("Weighted precision", 40)).append( StringUtils.leftPad(decimalFormatter.format(confusionMatrix.getWeightedPrecision()), 10)).append('\n'); returnString.append(StringUtils.rightPad("Weighted recall", 40)).append( StringUtils.leftPad(decimalFormatter.format(confusionMatrix.getWeightedRecall()), 10)).append('\n');
StringUtils.leftPad(decimalFormatter.format(normStats.getStandardDeviation()), 10)).append('\n'); returnString.append(StringUtils.rightPad("Weighted precision", 40)).append( StringUtils.leftPad(decimalFormatter.format(confusionMatrix.getWeightedPrecision()), 10)).append('\n'); returnString.append(StringUtils.rightPad("Weighted recall", 40)).append( StringUtils.leftPad(decimalFormatter.format(confusionMatrix.getWeightedRecall()), 10)).append('\n');
/** * Example taken from * http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html */ @Test public void testPrecisionRecallAndF1ScoreAsScikitLearn() { Collection<String> labelList = Arrays.asList("0", "1", "2"); ConfusionMatrix confusionMatrix = new ConfusionMatrix(labelList, "DEFAULT"); confusionMatrix.putCount("0", "0", 2); confusionMatrix.putCount("1", "0", 1); confusionMatrix.putCount("1", "2", 1); confusionMatrix.putCount("2", "1", 2); double delta = 0.001; assertEquals(0.222, confusionMatrix.getWeightedPrecision(), delta); assertEquals(0.333, confusionMatrix.getWeightedRecall(), delta); assertEquals(0.266, confusionMatrix.getWeightedF1score(), delta); }