20
20
21
21
import org .elasticsearch .client .ml .dataframe .evaluation .classification .AccuracyMetric ;
22
22
import org .elasticsearch .client .ml .dataframe .evaluation .classification .Classification ;
23
- import org .elasticsearch .client .ml .dataframe .evaluation .regression .MeanSquaredErrorMetric ;
24
23
import org .elasticsearch .client .ml .dataframe .evaluation .classification .MulticlassConfusionMatrixMetric ;
24
+ import org .elasticsearch .client .ml .dataframe .evaluation .regression .MeanSquaredErrorMetric ;
25
25
import org .elasticsearch .client .ml .dataframe .evaluation .regression .RSquaredMetric ;
26
26
import 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 ;
31
27
import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .AucRocMetric ;
28
+ import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .BinarySoftClassification ;
32
29
import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .ConfusionMatrixMetric ;
33
30
import org .elasticsearch .client .ml .dataframe .evaluation .softclassification .PrecisionMetric ;
34
31
import 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 ;
35
35
36
36
import java .util .Arrays ;
37
37
import java .util .List ;
38
38
39
39
public class MlEvaluationNamedXContentProvider implements NamedXContentProvider {
40
40
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
+
41
53
@ Override
42
54
public List <NamedXContentRegistry .Entry > getNamedXContentParsers () {
43
55
return Arrays .asList (
@@ -47,39 +59,91 @@ Evaluation.class, new ParseField(BinarySoftClassification.NAME), BinarySoftClass
47
59
new NamedXContentRegistry .Entry (Evaluation .class , new ParseField (Classification .NAME ), Classification ::fromXContent ),
48
60
new NamedXContentRegistry .Entry (Evaluation .class , new ParseField (Regression .NAME ), Regression ::fromXContent ),
49
61
// 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 ),
53
62
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 ),
55
66
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 ),
57
70
new NamedXContentRegistry .Entry (
58
71
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 )),
60
95
MulticlassConfusionMatrixMetric ::fromXContent ),
61
96
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 ),
63
100
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 ),
65
104
// Evaluation metrics results
66
105
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 ),
68
113
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 ),
70
117
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 ),
72
121
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 ),
74
125
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 ),
76
130
new NamedXContentRegistry .Entry (
77
131
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 )),
79
138
MulticlassConfusionMatrixMetric .Result ::fromXContent ),
80
139
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 ),
82
143
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
+ );
84
148
}
85
149
}
0 commit comments