@Test public void predResultLabelMapException() { HashSet<Object> set = new HashSet <>(); set.add("0"); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("The distinct label number less than 2!"); ClassificationEvaluationUtil.buildLabelIndexLabelArray(set, true, null, Types.INT); }
public static Tuple2<Map<Object, Integer>, Object[]> buildLabelIndexLabelArray(HashSet<Object> set, boolean binary, String positiveValue, TypeInformation labelType) { Object[] labels = set.toArray(); Arrays.sort(labels, Collections.reverseOrder()); Preconditions.checkArgument(labels.length >= 2, "The distinct label number less than 2!"); Preconditions.checkArgument(!binary || labels.length == BINARY_LABEL_NUMBER, "The number of labels must be equal to 2!"); Map<Object, Integer> map = new HashMap<>(labels.length); if (binary && null != positiveValue) { if (EvaluationUtil.labelCompare(labels[1], positiveValue, labelType)) { Object tmp = labels[1]; labels[1] = labels[0]; labels[0] = tmp; } else if (!EvaluationUtil.labelCompare(labels[0], positiveValue, labelType)) { throw new IllegalArgumentException("Not contain positiveValue"); } map.put(labels[0], 0); map.put(labels[1], 1); } else { for (int i = 0; i < labels.length; i++) { map.put(labels[i], i); } } return Tuple2.of(map, labels); }
ClassificationEvaluationUtil implements Serializable { public static Tuple2<Map<Object, Integer>, Object[]> buildLabelIndexLabelArray(HashSet<Object> set, boolean binary, String positiveValue, TypeInformation labelType) { Object[] labels = set.toArray(); Arrays.sort(labels, Collections.reverseOrder()); Preconditions.checkArgument(labels.length >= 2, "The distinct label number less than 2!"); Preconditions.checkArgument(!binary || labels.length == BINARY_LABEL_NUMBER, "The number of labels must be equal to 2!"); Map<Object, Integer> map = new HashMap<>(labels.length); if (binary && null != positiveValue) { if (EvaluationUtil.labelCompare(labels[1], positiveValue, labelType)) { Object tmp = labels[1]; labels[1] = labels[0]; labels[0] = tmp; } else if (!EvaluationUtil.labelCompare(labels[0], positiveValue, labelType)) { throw new IllegalArgumentException("Not contain positiveValue"); } map.put(labels[0], 0); map.put(labels[1], 1); } else { for (int i = 0; i < labels.length; i++) { map.put(labels[i], i); } } return Tuple2.of(map, labels); } }
ClassificationEvaluationUtil implements Serializable { public static Tuple2<Map<Object, Integer>, Object[]> buildLabelIndexLabelArray(HashSet<Object> set, boolean binary, String positiveValue, TypeInformation labelType) { Object[] labels = set.toArray(); Arrays.sort(labels, Collections.reverseOrder()); Preconditions.checkArgument(labels.length >= 2, "The distinct label number less than 2!"); Preconditions.checkArgument(!binary || labels.length == BINARY_LABEL_NUMBER, "The number of labels must be equal to 2!"); Map<Object, Integer> map = new HashMap<>(labels.length); if (binary && null != positiveValue) { if (EvaluationUtil.labelCompare(labels[1], positiveValue, labelType)) { Object tmp = labels[1]; labels[1] = labels[0]; labels[0] = tmp; } else if (!EvaluationUtil.labelCompare(labels[0], positiveValue, labelType)) { throw new IllegalArgumentException("Not contain positiveValue"); } map.put(labels[0], 0); map.put(labels[1], 1); } else { for (int i = 0; i < labels.length; i++) { map.put(labels[i], i); } } return Tuple2.of(map, labels); }  }
ClassificationEvaluationUtil implements Serializable { public static Tuple2<Map<Object, Integer>, Object[]> buildLabelIndexLabelArray(HashSet<Object> set, boolean binary, String positiveValue, TypeInformation labelType) { Object[] labels = set.toArray(); Arrays.sort(labels, Collections.reverseOrder()); Preconditions.checkArgument(labels.length >= 2, "The distinct label number less than 2!"); Preconditions.checkArgument(!binary || labels.length == BINARY_LABEL_NUMBER, "The number of labels must be equal to 2!"); Map<Object, Integer> map = new HashMap<>(labels.length); if (binary && null != positiveValue) { if (EvaluationUtil.labelCompare(labels[1], positiveValue, labelType)) { Object tmp = labels[1]; labels[1] = labels[0]; labels[0] = tmp; } else if (!EvaluationUtil.labelCompare(labels[0], positiveValue, labelType)) { throw new IllegalArgumentException("Not contain positiveValue"); } map.put(labels[0], 0); map.put(labels[1], 1); } else { for (int i = 0; i < labels.length; i++) { map.put(labels[i], i); } } return Tuple2.of(map, labels); }  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); }
ClassificationEvaluationUtil implements Serializable { public static Tuple2<Map<Object, Integer>, Object[]> buildLabelIndexLabelArray(HashSet<Object> set, boolean binary, String positiveValue, TypeInformation labelType) { Object[] labels = set.toArray(); Arrays.sort(labels, Collections.reverseOrder()); Preconditions.checkArgument(labels.length >= 2, "The distinct label number less than 2!"); Preconditions.checkArgument(!binary || labels.length == BINARY_LABEL_NUMBER, "The number of labels must be equal to 2!"); Map<Object, Integer> map = new HashMap<>(labels.length); if (binary && null != positiveValue) { if (EvaluationUtil.labelCompare(labels[1], positiveValue, labelType)) { Object tmp = labels[1]; labels[1] = labels[0]; labels[0] = tmp; } else if (!EvaluationUtil.labelCompare(labels[0], positiveValue, labelType)) { throw new IllegalArgumentException("Not contain positiveValue"); } map.put(labels[0], 0); map.put(labels[1], 1); } else { for (int i = 0; i < labels.length; i++) { map.put(labels[i], i); } } return Tuple2.of(map, labels); }  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; }