ClassificationEvaluationUtil implements Serializable { public static Tuple3<Double, Boolean, Double> getBinaryDetailStatistics(Row row, Object[] tuple, TypeInformation labelType) { Preconditions.checkArgument(tuple.length == 2, "Label length is not 2, Only support binary evaluation!"); if (EvaluationUtil.checkRowFieldNotNull(row)) { TreeMap<Object, Double> labelProbMap = EvaluationUtil.extractLabelProbMap(row, labelType); Object label = row.getField(0); Preconditions.checkState(labelProbMap.size() == BINARY_LABEL_NUMBER, "The number of labels must be equal to 2!"); double logLoss = EvaluationUtil.extractLogloss(labelProbMap, label); double d = labelProbMap.get(tuple[0]); if (label.equals(tuple[0])) { return Tuple3.of(d, true, logLoss); } else if (label.equals(tuple[1])) { return Tuple3.of(d, false, logLoss); } } return null; }  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 getDetailBinary(){ 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; Tuple3<Double, Boolean, Double> t = ClassificationEvaluationUtil.getBinaryDetailStatistics(rows[0], labels, labelType); Assert.assertEquals(t.f0, 0.9, 0.01); Assert.assertTrue(t.f1); t = ClassificationEvaluationUtil.getBinaryDetailStatistics(rows[4], labels, labelType); Assert.assertEquals(t.f0, 0.6, 0.01); Assert.assertFalse(t.f1); rows = new Row[] { Row.of(1.0, "{\"1.00\": 0.9, \"0.00\": 0.1}"), Row.of(1.00, "{\"1.0\": 0.8, \"0.00\": 0.2}"), Row.of(1.0, "{\"1.00\": 0.7, \"0.000\": 0.3}"), Row.of(0.0, "{\"1.0\": 0.75, \"0.0\": 0.25}"), Row.of(null, "{\"1.0\": 0.75, \"0.0\": 0.25}"), Row.of(0.00, "{\"1.0\": 0.6, \"0.00\": 0.4}") }; labels = new Object[]{1.0, 0.0}; labelType = Types.DOUBLE; t = ClassificationEvaluationUtil.getBinaryDetailStatistics(rows[1], labels, labelType); Assert.assertEquals(t.f0, 0.8, 0.01); Assert.assertTrue(t.f1); t = ClassificationEvaluationUtil.getBinaryDetailStatistics(rows[5], labels, labelType); Assert.assertEquals(t.f0, 0.6, 0.01); Assert.assertFalse(t.f1); }