19
19
20
20
package org .elasticsearch .client .ml .dataframe ;
21
21
22
- import org .elasticsearch .common .Nullable ;
23
22
import org .elasticsearch .common .ParseField ;
24
23
import org .elasticsearch .common .Strings ;
25
24
import org .elasticsearch .common .xcontent .ObjectParser ;
@@ -48,6 +47,9 @@ public static Builder builder() {
48
47
static final ParseField N_NEIGHBORS = new ParseField ("n_neighbors" );
49
48
static final ParseField METHOD = new ParseField ("method" );
50
49
public static final ParseField FEATURE_INFLUENCE_THRESHOLD = new ParseField ("feature_influence_threshold" );
50
+ static final ParseField COMPUTE_FEATURE_INFLUENCE = new ParseField ("compute_feature_influence" );
51
+ static final ParseField OUTLIER_FRACTION = new ParseField ("outlier_fraction" );
52
+ static final ParseField STANDARDIZATION_ENABLED = new ParseField ("standardization_enabled" );
51
53
52
54
private static ObjectParser <Builder , Void > PARSER = new ObjectParser <>(NAME .getPreferredName (), true , Builder ::new );
53
55
@@ -60,22 +62,49 @@ public static Builder builder() {
60
62
throw new IllegalArgumentException ("Unsupported token [" + p .currentToken () + "]" );
61
63
}, METHOD , ObjectParser .ValueType .STRING );
62
64
PARSER .declareDouble (Builder ::setFeatureInfluenceThreshold , FEATURE_INFLUENCE_THRESHOLD );
65
+ PARSER .declareBoolean (Builder ::setComputeFeatureInfluence , COMPUTE_FEATURE_INFLUENCE );
66
+ PARSER .declareDouble (Builder ::setOutlierFraction , OUTLIER_FRACTION );
67
+ PARSER .declareBoolean (Builder ::setStandardizationEnabled , STANDARDIZATION_ENABLED );
63
68
}
64
69
70
+ /**
71
+ * The number of neighbors. Leave unspecified for dynamic detection.
72
+ */
65
73
private final Integer nNeighbors ;
74
+
75
+ /**
76
+ * The method. Leave unspecified for a dynamic mixture of methods.
77
+ */
66
78
private final Method method ;
79
+
80
+ /**
81
+ * The min outlier score required to calculate feature influence. Defaults to 0.1.
82
+ */
67
83
private final Double featureInfluenceThreshold ;
68
84
69
85
/**
70
- * Constructs the outlier detection configuration
71
- * @param nNeighbors The number of neighbors. Leave unspecified for dynamic detection.
72
- * @param method The method. Leave unspecified for a dynamic mixture of methods.
73
- * @param featureInfluenceThreshold The min outlier score required to calculate feature influence. Defaults to 0.1.
86
+ * Whether to compute feature influence or not. Defaults to true.
74
87
*/
75
- private OutlierDetection (@ Nullable Integer nNeighbors , @ Nullable Method method , @ Nullable Double featureInfluenceThreshold ) {
88
+ private final Boolean computeFeatureInfluence ;
89
+
90
+ /**
91
+ * The proportion of data assumed to be outlying prior to outlier detection. Defaults to 0.05.
92
+ */
93
+ private final Double outlierFraction ;
94
+
95
+ /**
96
+ * Whether to perform standardization.
97
+ */
98
+ private final Boolean standardizationEnabled ;
99
+
100
+ private OutlierDetection (Integer nNeighbors , Method method , Double featureInfluenceThreshold , Boolean computeFeatureInfluence ,
101
+ Double outlierFraction , Boolean standardizationEnabled ) {
76
102
this .nNeighbors = nNeighbors ;
77
103
this .method = method ;
78
104
this .featureInfluenceThreshold = featureInfluenceThreshold ;
105
+ this .computeFeatureInfluence = computeFeatureInfluence ;
106
+ this .outlierFraction = outlierFraction ;
107
+ this .standardizationEnabled = standardizationEnabled ;
79
108
}
80
109
81
110
@ Override
@@ -95,6 +124,18 @@ public Double getFeatureInfluenceThreshold() {
95
124
return featureInfluenceThreshold ;
96
125
}
97
126
127
+ public Boolean getComputeFeatureInfluence () {
128
+ return computeFeatureInfluence ;
129
+ }
130
+
131
+ public Double getOutlierFraction () {
132
+ return outlierFraction ;
133
+ }
134
+
135
+ public Boolean getStandardizationEnabled () {
136
+ return standardizationEnabled ;
137
+ }
138
+
98
139
@ Override
99
140
public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
100
141
builder .startObject ();
@@ -107,6 +148,15 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
107
148
if (featureInfluenceThreshold != null ) {
108
149
builder .field (FEATURE_INFLUENCE_THRESHOLD .getPreferredName (), featureInfluenceThreshold );
109
150
}
151
+ if (computeFeatureInfluence != null ) {
152
+ builder .field (COMPUTE_FEATURE_INFLUENCE .getPreferredName (), computeFeatureInfluence );
153
+ }
154
+ if (outlierFraction != null ) {
155
+ builder .field (OUTLIER_FRACTION .getPreferredName (), outlierFraction );
156
+ }
157
+ if (standardizationEnabled != null ) {
158
+ builder .field (STANDARDIZATION_ENABLED .getPreferredName (), standardizationEnabled );
159
+ }
110
160
builder .endObject ();
111
161
return builder ;
112
162
}
@@ -119,12 +169,16 @@ public boolean equals(Object o) {
119
169
OutlierDetection other = (OutlierDetection ) o ;
120
170
return Objects .equals (nNeighbors , other .nNeighbors )
121
171
&& Objects .equals (method , other .method )
122
- && Objects .equals (featureInfluenceThreshold , other .featureInfluenceThreshold );
172
+ && Objects .equals (featureInfluenceThreshold , other .featureInfluenceThreshold )
173
+ && Objects .equals (computeFeatureInfluence , other .computeFeatureInfluence )
174
+ && Objects .equals (outlierFraction , other .outlierFraction )
175
+ && Objects .equals (standardizationEnabled , other .standardizationEnabled );
123
176
}
124
177
125
178
@ Override
126
179
public int hashCode () {
127
- return Objects .hash (nNeighbors , method , featureInfluenceThreshold );
180
+ return Objects .hash (nNeighbors , method , featureInfluenceThreshold , computeFeatureInfluence , outlierFraction ,
181
+ standardizationEnabled );
128
182
}
129
183
130
184
@ Override
@@ -150,6 +204,9 @@ public static class Builder {
150
204
private Integer nNeighbors ;
151
205
private Method method ;
152
206
private Double featureInfluenceThreshold ;
207
+ private Boolean computeFeatureInfluence ;
208
+ private Double outlierFraction ;
209
+ private Boolean standardizationEnabled ;
153
210
154
211
private Builder () {}
155
212
@@ -168,8 +225,24 @@ public Builder setFeatureInfluenceThreshold(Double featureInfluenceThreshold) {
168
225
return this ;
169
226
}
170
227
228
+ public Builder setComputeFeatureInfluence (Boolean computeFeatureInfluence ) {
229
+ this .computeFeatureInfluence = computeFeatureInfluence ;
230
+ return this ;
231
+ }
232
+
233
+ public Builder setOutlierFraction (Double outlierFraction ) {
234
+ this .outlierFraction = outlierFraction ;
235
+ return this ;
236
+ }
237
+
238
+ public Builder setStandardizationEnabled (Boolean standardizationEnabled ) {
239
+ this .standardizationEnabled = standardizationEnabled ;
240
+ return this ;
241
+ }
242
+
171
243
public OutlierDetection build () {
172
- return new OutlierDetection (nNeighbors , method , featureInfluenceThreshold );
244
+ return new OutlierDetection (nNeighbors , method , featureInfluenceThreshold , computeFeatureInfluence , outlierFraction ,
245
+ standardizationEnabled );
173
246
}
174
247
}
175
248
}
0 commit comments