ClassificationEvaluationUtil implements Serializable { public static void updateBinaryPartitionSummary(BinaryPartitionSummary statistics, Tuple3<Double, Boolean, Double> t){ if(!isMiddlePoint(t)) { if (t.f1) { statistics.curPositive++; } else { statistics.curNegative++; } } int compare = Double.compare(statistics.maxScore, t.f0); if(compare < 0){ statistics.maxScore = t.f0; } }  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 updateBinaryPartitionSummaryTest(){ Row[] rows = new Row[] { Row.of("prefix1", "{\"prefix1\": 0.9, \"prefix0\": 0.1}"), Row.of("prefix1", "{\"prefix1\": 0.8, \"prefix0\": 0.2}"), Row.of("prefix1", "{\"prefix1\": 0.7, \"prefix0\": 0.3}"), Row.of("prefix0", "{\"prefix1\": 0.75, \"prefix0\": 0.25}"), Row.of("prefix0", "{\"prefix1\": 0.6, \"prefix0\": 0.4}"), Row.of(null, "{\"prefix1\": 0.75, \"prefix0\": 0.25}"), }; Object[] labels = new Object[]{"prefix1", "prefix0"}; TypeInformation labelType = Types.STRING; ClassificationEvaluationUtil.BinaryPartitionSummary summary = new ClassificationEvaluationUtil .BinaryPartitionSummary(0, 0, 0, 0); for(Row row : rows){ Tuple3<Double, Boolean, Double> t = ClassificationEvaluationUtil.getBinaryDetailStatistics(row, labels, labelType); if(null != t) { ClassificationEvaluationUtil.updateBinaryPartitionSummary(summary, t); } } Assert.assertEquals(summary.curNegative, 2); Assert.assertEquals(summary.curPositive, 3); Assert.assertEquals((int)summary.taskId, 0); Assert.assertEquals(summary.maxScore, 0.9, 0.01); }