public interface Evaluator extends HasInputFields, HasResultFields
Performs the evaluation of a Model.
PMML pmml = ...; EvaluatorBuilder evaluatorBuilder = new ModelEvaluatorBuilder(pmml); Evaluator evaluator = evaluatorBuilder.build(); evaluator.verify();Preparing arguments
Map<String, ?> userArguments = ...;
Map<String, FieldValue> arguments = new LinkedHashMap<>();
List<InputField> inputFields = evaluator.getInputFields();
for(InputField inputField : inputFields){
String inputName = inputField.getName();
Object rawValue = userArguments.get(inputName);
FieldValue inputValue = inputField.prepare(rawValue);
arguments.put(inputName, inputValue);
}
Performing the evaluation
Map<String, ?> results = evaluator.evaluate(arguments);Processing results
target fields (ie. primary results):
List<TargetField> targetFields = evaluator.getTargetFields();
for(TargetField targetField : targetFields){
String targetName = targetField.getName();
Object targetValue = results.get(targetName);
}
Decoding a complex value to a Java primitive value:
if(targetValue instanceof Computable){
Computable computable = (Computable)targetValue;
targetValue = computable.getResult();
}
Retrieving the values of output fields (ie. secondary results):
List<OutputField> outputFields = evaluator.getOutputFields();
for(OutputField outputField : outputFields){
String outputName = outputField.getName();
Object outputValue = results.get(outputName);
}
Handling exceptions
EvaluationException instances that indicate "local" problems, which are related to individual data records.
The outer try statement should catch InvalidMarkupException and UnsupportedMarkupException instances that indicate "global" problems, which are related to the class model object.
try {
List<Map<String, ?>> records = ...;
for(Map<String, ?> record : records){
try {
// Do exception-prone work
} catch(EvaluationException ee){
// The work failed because of the data record.
// Skip this data record and proceed as usual with the next one
}
}
} catch(InvalidMarkupException | UnsupportedMarkupException me){
// The work failed because of the class model object.
// This is a persistent problem that is very likely to affect all data records
// Decommission the Evaluator instance
}
EvaluatorUtil,
HasGroupFields,
HasOrderFields,
HasPMML,
HasModel| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_TARGET_NAME
The name of the default target field.
|
| Modifier and Type | Method and Description |
|---|---|
Map<String,?> |
evaluate(Map<String,?> arguments)
Evaluates the model with the specified arguments.
|
org.dmg.pmml.MiningFunction |
getMiningFunction()
Gets the type of the
Model. |
String |
getSummary()
Gets a short description of the
Model. |
Evaluator |
verify()
Verifies the model.
|
getInputFieldsgetActiveFieldsgetOutputFields, getTargetFieldsstatic final String DEFAULT_TARGET_NAME
The name of the default target field.
String getSummary()
Gets a short description of the Model.
org.dmg.pmml.MiningFunction getMiningFunction()
Gets the type of the Model.
Evaluator verify()
Verifies the model.
EvaluationException - If the verification fails.InvalidMarkupExceptionUnsupportedMarkupExceptionMap<String,?> evaluate(Map<String,?> arguments)
Evaluates the model with the specified arguments.
arguments - Map of input field values.target field and output field values.
A target field could be mapped to a complex value or a simple value.
An output field is always mapped to a simple value.
Complex values are represented as instances of Computable that return simple values.
Simple values are represented using the Java equivalents of PMML data types (eg. String, Integer, Float, Double etc.).
A missing value is represented by null.EvaluationException - If the evaluation fails.InvalidMarkupExceptionUnsupportedMarkupExceptionComputableCopyright © 2021. All rights reserved.