@Test public void testOneDifferentButBalanced() { Metric<Double> scoreCalculator = new ROCAUC(); LabelPairCursor<Double> cursor = new TestLabelPairCursor<>( Arrays.asList(1.0, 1.0, 0.0, 0.0), Arrays.asList(1.0, 1.0, 0.0, 1.0) ); double score = scoreCalculator.score(cursor.iterator()); assertEquals(0.75, score, 1e-12); }
@Override public double score(Iterator<LabelPair<Double>> iter) { PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey)); long pos = 0; long neg = 0; while (iter.hasNext()) { LabelPair<Double> e = iter.next(); Double prediction = e.getPrediction(); Double truth = e.getTruth(); queue.add(new Pair<>(prediction, truth)); if (truth == positiveClsLb) pos++; else if (truth == negativeClsLb) neg++; else throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); } return calculateROCAUC(queue, pos, neg, positiveClsLb); }
ROCAUC implements Metric<Double> { @Override public double score(Iterator<LabelPair<Double>> iter) { PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey)); long pos = 0; long neg = 0; while (iter.hasNext()) { LabelPair<Double> e = iter.next(); Double prediction = e.getPrediction(); Double truth = e.getTruth(); queue.add(new Pair<>(prediction, truth)); if (truth == positiveClsLb) pos++; else if (truth == negativeClsLb) neg++; else throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); } return calculateROCAUC(queue, pos, neg, positiveClsLb); } }
ROCAUC implements Metric<Double> { @Override public double score(Iterator<LabelPair<Double>> iter) { PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey)); long pos = 0; long neg = 0; while (iter.hasNext()) { LabelPair<Double> e = iter.next(); Double prediction = e.getPrediction(); Double truth = e.getTruth(); queue.add(new Pair<>(prediction, truth)); if (truth == positiveClsLb) pos++; else if (truth == negativeClsLb) neg++; else throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); } return calculateROCAUC(queue, pos, neg, positiveClsLb); }  }
ROCAUC implements Metric<Double> { @Override public double score(Iterator<LabelPair<Double>> iter) { PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey)); long pos = 0; long neg = 0; while (iter.hasNext()) { LabelPair<Double> e = iter.next(); Double prediction = e.getPrediction(); Double truth = e.getTruth(); queue.add(new Pair<>(prediction, truth)); if (truth == positiveClsLb) pos++; else if (truth == negativeClsLb) neg++; else throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); } return calculateROCAUC(queue, pos, neg, positiveClsLb); }  @Override double score(Iterator<LabelPair<Double>> iter); static double calculateROCAUC(PriorityQueue<Pair<Double, Double>> queue, long pos, long neg, double positiveClsLb); double positiveClsLb(); ROCAUC withPositiveClsLb(double positiveClsLb); double negativeClsLb(); ROCAUC withNegativeClsLb(double negativeClsLb); @Override String name(); }
ROCAUC implements Metric<Double> { @Override public double score(Iterator<LabelPair<Double>> iter) { PriorityQueue<Pair<Double, Double>> queue = new PriorityQueue<>(Comparator.comparingDouble(Pair::getKey)); long pos = 0; long neg = 0; while (iter.hasNext()) { LabelPair<Double> e = iter.next(); Double prediction = e.getPrediction(); Double truth = e.getTruth(); queue.add(new Pair<>(prediction, truth)); if (truth == positiveClsLb) pos++; else if (truth == negativeClsLb) neg++; else throw new UnknownClassLabelException(truth, positiveClsLb, negativeClsLb); } return calculateROCAUC(queue, pos, neg, positiveClsLb); }  @Override double score(Iterator<LabelPair<Double>> iter); static double calculateROCAUC(PriorityQueue<Pair<Double, Double>> queue, long pos, long neg, double positiveClsLb); double positiveClsLb(); ROCAUC withPositiveClsLb(double positiveClsLb); double negativeClsLb(); ROCAUC withNegativeClsLb(double negativeClsLb); @Override String name();  }