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();
Map<String, ?> userArguments = ...;
Map<FieldName, FieldValue> arguments = new LinkedHashMap<>();
List<? extends InputField> inputFields = evaluator.getInputFields();
for(InputField inputField : inputFields){
FieldName inputName = inputField.getName();
Object rawValue = userArguments.get(inputName.getValue());
FieldValue inputValue = inputField.prepare(rawValue);
arguments.put(inputName, inputValue);
}
Map<FieldName, ?> results = evaluator.evaluate(arguments);
target fields (ie. primary results):
List<? extends TargetField> targetFields = evaluator.getTargetFields();
for(TargetField targetField : targetFields){
FieldName 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<? extends OutputField> outputFields = evaluator.getOutputFields();
for(OutputField outputField : outputFields){
FieldName outputName = outputField.getName();
Object outputValue = results.get(outputName);
}
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,
HasModel,
HasPMML| Modifier and Type | Field and Description |
|---|---|
static org.dmg.pmml.FieldName |
DEFAULT_TARGET_NAME
The name of the default target field.
|
| Modifier and Type | Method and Description |
|---|---|
Map<org.dmg.pmml.FieldName,?> |
evaluate(Map<org.dmg.pmml.FieldName,?> 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 org.dmg.pmml.FieldName 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<org.dmg.pmml.FieldName,?> evaluate(Map<org.dmg.pmml.FieldName,?> 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 © 2020. All rights reserved.