ClassificationEvaluationUtil implements Serializable { public static Tuple2<Boolean, long[]> reduceBinaryPartitionSummary(List<BinaryPartitionSummary> values, int taskId) { List<BinaryPartitionSummary> list = new ArrayList<>(); values.forEach(list::add); list.sort(Comparator.comparingDouble(t -> -t.maxScore)); long curTrue = 0; long curFalse = 0; long totalTrue = 0; long totalFalse = 0; boolean firstBin = true; for(BinaryPartitionSummary statistics : list){ if(statistics.taskId == taskId){ firstBin = (totalTrue + totalFalse == 0); curFalse = totalFalse; curTrue = totalTrue; } totalTrue += statistics.curPositive; totalFalse += statistics.curNegative; } return Tuple2.of(firstBin, new long[]{curTrue, curFalse, totalTrue, totalFalse}); }  static Tuple3<Double, Boolean, Double> getBinaryDetailStatistics(Row row,
                                                                            Object[] tuple,
                                                                            TypeInformation labelType); static Tuple2<Map<Object, Integer>, Object[]> buildLabelIndexLabelArray(HashSet<Object> set,
                                                                                   boolean binary,
                                                                                   String positiveValue,
                                                                                   TypeInformation labelType); static Tuple2<Boolean, long[]> reduceBinaryPartitionSummary(List<BinaryPartitionSummary> values, int taskId); static boolean isMiddlePoint(Tuple3<Double, Boolean, Double> t); static void updateBinaryPartitionSummary(BinaryPartitionSummary statistics,
                                                    Tuple3<Double, Boolean, Double> t); static void updateAccurateBinaryMetricsSummary(Tuple3<Double, Boolean, Double> cur,
                                                          AccurateBinaryMetricsSummary binaryMetricsSummary,
                                                          long[] countValues,
                                                          double[] recordValues,
                                                          boolean first); static int DETAIL_BIN_NUMBER; static int TOTAL_TRUE; static int TOTAL_FALSE; static int CUR_TRUE; static int CUR_FALSE; static int RECORD_LEN; static int BINARY_LABEL_NUMBER; static Tuple3<Double, Boolean, Double> middlePoint; }
@Test public void reduceBinaryPartitionSummaryTest(){ List<ClassificationEvaluationUtil.BinaryPartitionSummary> list = new ArrayList<>(); ClassificationEvaluationUtil.BinaryPartitionSummary summary1 = new ClassificationEvaluationUtil .BinaryPartitionSummary(0, 0.9, 5, 3); list.add(summary1); ClassificationEvaluationUtil.BinaryPartitionSummary summary2 = new ClassificationEvaluationUtil .BinaryPartitionSummary(1, 0.7, 4, 1); list.add(summary2); ClassificationEvaluationUtil.BinaryPartitionSummary summary3 = new ClassificationEvaluationUtil .BinaryPartitionSummary(2, 0.4, 3, 6); list.add(summary3); Tuple2<Boolean, long[]> t = ClassificationEvaluationUtil.reduceBinaryPartitionSummary(list, 0); Assert.assertTrue(t.f0); Assert.assertArrayEquals(t.f1, new long[]{0, 0, 12, 10}); t = ClassificationEvaluationUtil.reduceBinaryPartitionSummary(list, 2); Assert.assertFalse(t.f0); Assert.assertArrayEquals(t.f1, new long[]{9, 4, 12, 10}); }