2020
2121import org .elasticsearch .client .ml .dataframe .evaluation .classification .AccuracyMetric ;
2222import org .elasticsearch .client .ml .dataframe .evaluation .classification .Classification ;
23- import org .elasticsearch .client .ml .dataframe .evaluation .regression .MeanSquaredErrorMetric ;
2423import org .elasticsearch .client .ml .dataframe .evaluation .classification .MulticlassConfusionMatrixMetric ;
24+ import org .elasticsearch .client .ml .dataframe .evaluation .regression .MeanSquaredErrorMetric ;
2525import org .elasticsearch .client .ml .dataframe .evaluation .regression .RSquaredMetric ;
2626import org .elasticsearch .client .ml .dataframe .evaluation .regression .Regression ;
27- import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .BinarySoftClassification ;
28- import org .elasticsearch .common .ParseField ;
29- import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
30- import org .elasticsearch .plugins .spi .NamedXContentProvider ;
3127import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .AucRocMetric ;
28+ import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .BinarySoftClassification ;
3229import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .ConfusionMatrixMetric ;
3330import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .PrecisionMetric ;
3431import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .RecallMetric ;
32+ import org .elasticsearch .common .ParseField ;
33+ import org .elasticsearch .common .xcontent .NamedXContentRegistry ;
34+ import org .elasticsearch .plugins .spi .NamedXContentProvider ;
3535
3636import java .util .Arrays ;
3737import java .util .List ;
3838
3939public class MlEvaluationNamedXContentProvider implements NamedXContentProvider {
4040
41+ /**
42+ * Constructs the name under which a metric (or metric result) is registered.
43+ * The name is prefixed with evaluation name so that registered names are unique.
44+ *
45+ * @param evaluationName name of the evaluation
46+ * @param metricName name of the metric
47+ * @return name appropriate for registering a metric (or metric result) in {@link NamedXContentRegistry}
48+ */
49+ public static String registeredMetricName (String evaluationName , String metricName ) {
50+ return evaluationName + "." + metricName ;
51+ }
52+
4153 @ Override
4254 public List <NamedXContentRegistry .Entry > getNamedXContentParsers () {
4355 return Arrays .asList (
@@ -47,39 +59,91 @@ Evaluation.class, new ParseField(BinarySoftClassification.NAME), BinarySoftClass
4759 new NamedXContentRegistry .Entry (Evaluation .class , new ParseField (Classification .NAME ), Classification ::fromXContent ),
4860 new NamedXContentRegistry .Entry (Evaluation .class , new ParseField (Regression .NAME ), Regression ::fromXContent ),
4961 // Evaluation metrics
50- new NamedXContentRegistry .Entry (EvaluationMetric .class , new ParseField (AucRocMetric .NAME ), AucRocMetric ::fromXContent ),
51- new NamedXContentRegistry .Entry (EvaluationMetric .class , new ParseField (PrecisionMetric .NAME ), PrecisionMetric ::fromXContent ),
52- new NamedXContentRegistry .Entry (EvaluationMetric .class , new ParseField (RecallMetric .NAME ), RecallMetric ::fromXContent ),
5362 new NamedXContentRegistry .Entry (
54- EvaluationMetric .class , new ParseField (ConfusionMatrixMetric .NAME ), ConfusionMatrixMetric ::fromXContent ),
63+ EvaluationMetric .class ,
64+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , AucRocMetric .NAME )),
65+ AucRocMetric ::fromXContent ),
5566 new NamedXContentRegistry .Entry (
56- EvaluationMetric .class , new ParseField (AccuracyMetric .NAME ), AccuracyMetric ::fromXContent ),
67+ EvaluationMetric .class ,
68+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , PrecisionMetric .NAME )),
69+ PrecisionMetric ::fromXContent ),
5770 new NamedXContentRegistry .Entry (
5871 EvaluationMetric .class ,
59- new ParseField (MulticlassConfusionMatrixMetric .NAME ),
72+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , RecallMetric .NAME )),
73+ RecallMetric ::fromXContent ),
74+ new NamedXContentRegistry .Entry (
75+ EvaluationMetric .class ,
76+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , ConfusionMatrixMetric .NAME )),
77+ ConfusionMatrixMetric ::fromXContent ),
78+ new NamedXContentRegistry .Entry (
79+ EvaluationMetric .class ,
80+ new ParseField (registeredMetricName (Classification .NAME , AccuracyMetric .NAME )),
81+ AccuracyMetric ::fromXContent ),
82+ new NamedXContentRegistry .Entry (
83+ EvaluationMetric .class ,
84+ new ParseField (registeredMetricName (
85+ Classification .NAME , org .elasticsearch .client .ml .dataframe .evaluation .classification .PrecisionMetric .NAME )),
86+ org .elasticsearch .client .ml .dataframe .evaluation .classification .PrecisionMetric ::fromXContent ),
87+ new NamedXContentRegistry .Entry (
88+ EvaluationMetric .class ,
89+ new ParseField (registeredMetricName (
90+ Classification .NAME , org .elasticsearch .client .ml .dataframe .evaluation .classification .RecallMetric .NAME )),
91+ org .elasticsearch .client .ml .dataframe .evaluation .classification .RecallMetric ::fromXContent ),
92+ new NamedXContentRegistry .Entry (
93+ EvaluationMetric .class ,
94+ new ParseField (registeredMetricName (Classification .NAME , MulticlassConfusionMatrixMetric .NAME )),
6095 MulticlassConfusionMatrixMetric ::fromXContent ),
6196 new NamedXContentRegistry .Entry (
62- EvaluationMetric .class , new ParseField (MeanSquaredErrorMetric .NAME ), MeanSquaredErrorMetric ::fromXContent ),
97+ EvaluationMetric .class ,
98+ new ParseField (registeredMetricName (Regression .NAME , MeanSquaredErrorMetric .NAME )),
99+ MeanSquaredErrorMetric ::fromXContent ),
63100 new NamedXContentRegistry .Entry (
64- EvaluationMetric .class , new ParseField (RSquaredMetric .NAME ), RSquaredMetric ::fromXContent ),
101+ EvaluationMetric .class ,
102+ new ParseField (registeredMetricName (Regression .NAME , RSquaredMetric .NAME )),
103+ RSquaredMetric ::fromXContent ),
65104 // Evaluation metrics results
66105 new NamedXContentRegistry .Entry (
67- EvaluationMetric .Result .class , new ParseField (AucRocMetric .NAME ), AucRocMetric .Result ::fromXContent ),
106+ EvaluationMetric .Result .class ,
107+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , AucRocMetric .NAME )),
108+ AucRocMetric .Result ::fromXContent ),
109+ new NamedXContentRegistry .Entry (
110+ EvaluationMetric .Result .class ,
111+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , PrecisionMetric .NAME )),
112+ PrecisionMetric .Result ::fromXContent ),
68113 new NamedXContentRegistry .Entry (
69- EvaluationMetric .Result .class , new ParseField (PrecisionMetric .NAME ), PrecisionMetric .Result ::fromXContent ),
114+ EvaluationMetric .Result .class ,
115+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , RecallMetric .NAME )),
116+ RecallMetric .Result ::fromXContent ),
70117 new NamedXContentRegistry .Entry (
71- EvaluationMetric .Result .class , new ParseField (RecallMetric .NAME ), RecallMetric .Result ::fromXContent ),
118+ EvaluationMetric .Result .class ,
119+ new ParseField (registeredMetricName (BinarySoftClassification .NAME , ConfusionMatrixMetric .NAME )),
120+ ConfusionMatrixMetric .Result ::fromXContent ),
72121 new NamedXContentRegistry .Entry (
73- EvaluationMetric .Result .class , new ParseField (ConfusionMatrixMetric .NAME ), ConfusionMatrixMetric .Result ::fromXContent ),
122+ EvaluationMetric .Result .class ,
123+ new ParseField (registeredMetricName (Classification .NAME , AccuracyMetric .NAME )),
124+ AccuracyMetric .Result ::fromXContent ),
74125 new NamedXContentRegistry .Entry (
75- EvaluationMetric .Result .class , new ParseField (AccuracyMetric .NAME ), AccuracyMetric .Result ::fromXContent ),
126+ EvaluationMetric .Result .class ,
127+ new ParseField (registeredMetricName (
128+ Classification .NAME , org .elasticsearch .client .ml .dataframe .evaluation .classification .PrecisionMetric .NAME )),
129+ org .elasticsearch .client .ml .dataframe .evaluation .classification .PrecisionMetric .Result ::fromXContent ),
76130 new NamedXContentRegistry .Entry (
77131 EvaluationMetric .Result .class ,
78- new ParseField (MulticlassConfusionMatrixMetric .NAME ),
132+ new ParseField (registeredMetricName (
133+ Classification .NAME , org .elasticsearch .client .ml .dataframe .evaluation .classification .RecallMetric .NAME )),
134+ org .elasticsearch .client .ml .dataframe .evaluation .classification .RecallMetric .Result ::fromXContent ),
135+ new NamedXContentRegistry .Entry (
136+ EvaluationMetric .Result .class ,
137+ new ParseField (registeredMetricName (Classification .NAME , MulticlassConfusionMatrixMetric .NAME )),
79138 MulticlassConfusionMatrixMetric .Result ::fromXContent ),
80139 new NamedXContentRegistry .Entry (
81- EvaluationMetric .Result .class , new ParseField (MeanSquaredErrorMetric .NAME ), MeanSquaredErrorMetric .Result ::fromXContent ),
140+ EvaluationMetric .Result .class ,
141+ new ParseField (registeredMetricName (Regression .NAME , MeanSquaredErrorMetric .NAME )),
142+ MeanSquaredErrorMetric .Result ::fromXContent ),
82143 new NamedXContentRegistry .Entry (
83- EvaluationMetric .Result .class , new ParseField (RSquaredMetric .NAME ), RSquaredMetric .Result ::fromXContent ));
144+ EvaluationMetric .Result .class ,
145+ new ParseField (registeredMetricName (Regression .NAME , RSquaredMetric .NAME )),
146+ RSquaredMetric .Result ::fromXContent )
147+ );
84148 }
85149}
0 commit comments