BinaryClassificationMetrics extends AbstractMetrics<BinaryClassificationMetricValues> { @Override public BinaryClassificationMetricValues scoreAll(Iterator<LabelPair<Double>> iter) { long tp = 0; long tn = 0; long fp = 0; long fn = 0; double rocauc = Double.NaN; long pos = 0; long neg = 0; PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey)); while (iter.hasNext()) { LabelPair<Double> e = iter.next(); double prediction = e.getPrediction(); double truth = e.getTruth(); if (prediction != negativeClsLb && prediction != positiveClsLb) throw new UnknownClassLabelException(prediction, positiveClsLb, negativeClsLb); if (truth != negativeClsLb && truth != positiveClsLb) throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); if (truth == positiveClsLb && prediction == positiveClsLb) tp++; else if (truth == positiveClsLb && prediction == negativeClsLb) fn++; else if (truth == negativeClsLb && prediction == negativeClsLb) tn++; else if (truth == negativeClsLb && prediction == positiveClsLb) fp++; if (enableROCAUC) { queue.add(new Pair<>(prediction, truth)); if (truth == positiveClsLb) pos++; else if (truth == negativeClsLb) neg++; else throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); } } if (enableROCAUC) rocauc = ROCAUC.calculateROCAUC(queue, pos, neg, positiveClsLb); return new BinaryClassificationMetricValues(tp, tn, fp, fn, rocauc); }  @Override BinaryClassificationMetricValues scoreAll(Iterator<LabelPair<Double>> iter); double positiveClsLb(); BinaryClassificationMetrics withPositiveClsLb(double positiveClsLb); double negativeClsLb(); BinaryClassificationMetrics withNegativeClsLb(double negativeClsLb); BinaryClassificationMetrics withEnablingROCAUC(boolean enableROCAUC); boolean isROCAUCenabled(); @Override String name();  }
@Test public void testDefaultBehaviourForScoreAll() { BinaryClassificationMetrics scoreCalculator = new BinaryClassificationMetrics(); LabelPairCursor<Double> cursor = new TestLabelPairCursor<>( Arrays.asList(1.0, 1.0, 1.0, 1.0), Arrays.asList(1.0, 1.0, 0.0, 1.0) ); BinaryClassificationMetricValues metricValues = scoreCalculator.scoreAll(cursor.iterator()); assertEquals(0.75, metricValues.accuracy(), 1e-12); }