[ML] Make Ensemble feature names optional (#51996)
The featureNames field is requisite in individual models but is not required by the Ensemble.
This commit is contained in:
parent
91e938ead8
commit
8f10a7c6ca
|
@ -103,7 +103,7 @@ public class Ensemble implements TrainedModel {
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject();
|
||||
if (featureNames != null) {
|
||||
if (featureNames != null && featureNames.isEmpty() == false) {
|
||||
builder.field(FEATURE_NAMES.getPreferredName(), featureNames);
|
||||
}
|
||||
if (models != null) {
|
||||
|
@ -157,7 +157,7 @@ public class Ensemble implements TrainedModel {
|
|||
}
|
||||
|
||||
public static class Builder {
|
||||
private List<String> featureNames;
|
||||
private List<String> featureNames = Collections.emptyList();
|
||||
private List<TrainedModel> trainedModels;
|
||||
private OutputAggregator outputAggregator;
|
||||
private TargetType targetType;
|
||||
|
|
|
@ -86,7 +86,7 @@ public class EnsembleTests extends AbstractXContentTestCase<Ensemble> {
|
|||
.toArray() :
|
||||
null;
|
||||
|
||||
return new Ensemble(featureNames,
|
||||
return new Ensemble(randomBoolean() ? featureNames : Collections.emptyList(),
|
||||
models,
|
||||
outputAggregator,
|
||||
targetType,
|
||||
|
|
|
@ -150,7 +150,7 @@ See <<ml-put-inference-preprocessor-example>> for more details.
|
|||
The definition for a binary decision tree.
|
||||
|
||||
`tree`.`feature_names`:::
|
||||
(Required, string)
|
||||
(Required, string)
|
||||
Features expected by the tree, in their expected order.
|
||||
|
||||
`tree`.`tree_structure`:::
|
||||
|
@ -221,7 +221,7 @@ children).
|
|||
The definition for an ensemble model.
|
||||
|
||||
`ensemble`.`feature_names`:::
|
||||
(Required, string)
|
||||
(Optional, string)
|
||||
Features expected by the ensemble, in their expected order.
|
||||
|
||||
`ensemble`.`trained_models`:::
|
||||
|
|
|
@ -207,7 +207,9 @@ public class Ensemble implements LenientlyParsedTrainedModel, StrictlyParsedTrai
|
|||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
builder.field(FEATURE_NAMES.getPreferredName(), featureNames);
|
||||
if (featureNames.isEmpty() == false) {
|
||||
builder.field(FEATURE_NAMES.getPreferredName(), featureNames);
|
||||
}
|
||||
NamedXContentObjectHelper.writeNamedObjects(builder, params, true, TRAINED_MODELS.getPreferredName(), models);
|
||||
NamedXContentObjectHelper.writeNamedObjects(builder,
|
||||
params,
|
||||
|
@ -327,8 +329,9 @@ public class Ensemble implements LenientlyParsedTrainedModel, StrictlyParsedTrai
|
|||
private double[] classificationWeights;
|
||||
private boolean modelsAreOrdered;
|
||||
|
||||
private Builder (boolean modelsAreOrdered) {
|
||||
private Builder(boolean modelsAreOrdered) {
|
||||
this.modelsAreOrdered = modelsAreOrdered;
|
||||
this.featureNames = Collections.emptyList();
|
||||
}
|
||||
|
||||
private static Builder builderForParser() {
|
||||
|
|
|
@ -92,7 +92,7 @@ public class EnsembleTests extends AbstractSerializingTestCase<Ensemble> {
|
|||
.toArray() :
|
||||
null;
|
||||
|
||||
return new Ensemble(featureNames,
|
||||
return new Ensemble(randomBoolean() ? featureNames : Collections.emptyList(),
|
||||
models,
|
||||
outputAggregator,
|
||||
targetType,
|
||||
|
|
Loading…
Reference in New Issue