Skip to content

Commit 00541d9

Browse files
committed
Apply review comments
1 parent f321d4f commit 00541d9

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/analyses/BoostedTreeParams.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ static void declareFields(AbstractObjectParser<?, Void> parser) {
7676
this.featureBagFraction = featureBagFraction;
7777
}
7878

79+
BoostedTreeParams() {
80+
this(null, null, null, null, null);
81+
}
82+
7983
BoostedTreeParams(StreamInput in) throws IOException {
8084
lambda = in.readOptionalDouble();
8185
gamma = in.readOptionalDouble();

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/analyses/Classification.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static Classification fromXContent(XContentParser parser, boolean ignoreU
6161
private final String dependentVariable;
6262
private final BoostedTreeParams boostedTreeParams;
6363
private final String predictionFieldName;
64-
private final Integer numTopClasses;
64+
private final int numTopClasses;
6565
private final double trainingPercent;
6666

6767
public Classification(String dependentVariable,
@@ -78,12 +78,12 @@ public Classification(String dependentVariable,
7878
this.dependentVariable = ExceptionsHelper.requireNonNull(dependentVariable, DEPENDENT_VARIABLE);
7979
this.boostedTreeParams = ExceptionsHelper.requireNonNull(boostedTreeParams, BoostedTreeParams.NAME);
8080
this.predictionFieldName = predictionFieldName;
81-
this.numTopClasses = numTopClasses;
81+
this.numTopClasses = numTopClasses == null ? 0 : numTopClasses;
8282
this.trainingPercent = trainingPercent == null ? 100.0 : trainingPercent;
8383
}
8484

8585
public Classification(String dependentVariable) {
86-
this(dependentVariable, new BoostedTreeParams(null, null, null, null, null), null, null, null);
86+
this(dependentVariable, new BoostedTreeParams(), null, null, null);
8787
}
8888

8989
public Classification(StreamInput in) throws IOException {
@@ -121,9 +121,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
121121
builder.startObject();
122122
builder.field(DEPENDENT_VARIABLE.getPreferredName(), dependentVariable);
123123
boostedTreeParams.toXContent(builder, params);
124-
if (numTopClasses != null) {
125-
builder.field(NUM_TOP_CLASSES.getPreferredName(), numTopClasses);
126-
}
124+
builder.field(NUM_TOP_CLASSES.getPreferredName(), numTopClasses);
127125
if (predictionFieldName != null) {
128126
builder.field(PREDICTION_FIELD_NAME.getPreferredName(), predictionFieldName);
129127
}
@@ -137,9 +135,7 @@ public Map<String, Object> getParams() {
137135
Map<String, Object> params = new HashMap<>();
138136
params.put(DEPENDENT_VARIABLE.getPreferredName(), dependentVariable);
139137
params.putAll(boostedTreeParams.getParams());
140-
if (numTopClasses != null) {
141-
params.put(NUM_TOP_CLASSES.getPreferredName(), numTopClasses);
142-
}
138+
params.put(NUM_TOP_CLASSES.getPreferredName(), numTopClasses);
143139
if (predictionFieldName != null) {
144140
params.put(PREDICTION_FIELD_NAME.getPreferredName(), predictionFieldName);
145141
}

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/analyses/Regression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Regression(String dependentVariable,
7474
}
7575

7676
public Regression(String dependentVariable) {
77-
this(dependentVariable, new BoostedTreeParams(null, null, null, null, null), null, null);
77+
this(dependentVariable, new BoostedTreeParams(), null, null);
7878
}
7979

8080
public Regression(StreamInput in) throws IOException {

x-pack/plugin/src/test/resources/rest-api-spec/test/ml/data_frame_analytics_crud.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,8 @@ setup:
15641564
"eta": 0.5,
15651565
"maximum_number_trees": 400,
15661566
"feature_bag_fraction": 0.3,
1567-
"training_percent": 60.3
1567+
"training_percent": 60.3,
1568+
"num_top_classes": 0
15681569
}
15691570
}}
15701571
- is_true: create_time

0 commit comments

Comments
 (0)