Package org.jpmml.evaluator
Interface Evaluator
-
- All Superinterfaces:
HasInputFields,HasResultFields
- All Known Implementing Classes:
AssociationModelEvaluator,ClusteringModelEvaluator,ComplexTreeModelEvaluator,GeneralRegressionModelEvaluator,JavaModelEvaluator,MiningModelEvaluator,ModelEvaluator,NaiveBayesModelEvaluator,NearestNeighborModelEvaluator,NeuralNetworkEvaluator,RegressionModelEvaluator,RuleSetModelEvaluator,ScorecardEvaluator,SimpleTreeModelEvaluator,SupportVectorMachineModelEvaluator,TimeSeriesModelEvaluator,TreeModelEvaluator
public interface Evaluator extends HasInputFields, HasResultFields
Performs the evaluation of a
Building and verifying an Evaluator instanceModel.
Preparing argumentsEvaluatorBuilder evaluatorBuilder = new LoadingModelEvaluatorBuilder() .load(new File("model.pmml")); Evaluator evaluator = evaluatorBuilder.build(); evaluator.verify();
Transforming an user-supplied map of arguments to a known-good PMML map of arguments:
Performing the evaluationMap<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); }
Processing resultsMap<String, ?> results = evaluator.evaluate(arguments);
Retrieving the values oftarget fields(ie. primary results):
Decoding aList<TargetField> targetFields = evaluator.getTargetFields(); for(TargetField targetField : targetFields){ String targetName = targetField.getName(); Object targetValue = results.get(targetName); }complex valueto a Java primitive value:
Retrieving the values ofif(targetValue instanceof Computable){ Computable computable = (Computable)targetValue; targetValue = computable.getResult(); }output fields(ie. secondary results):
Handling exceptionsList<OutputField> outputFields = evaluator.getOutputFields(); for(OutputField outputField : outputFields){ String outputName = outputField.getName(); Object outputValue = results.get(outputName); }
A code block that does exception-prone work should be surrounded with two levels of try-catch statements. The inner try statement should catchEvaluationExceptioninstances that indicate "local" problems, which are related to individual data records. The outer try statement should catchMarkupExceptioninstances that indicate "global" problems, which are related to the class model object.try { Lis<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(MarkupException 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 }- See Also:
EvaluatorUtil,HasGroupFields,HasOrderFields,HasPMML,HasModel
-
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_TARGET_NAMEThe name of the default target field.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Map<String,?>evaluate(Map<String,?> arguments)Evaluates the model with the specified arguments.org.dmg.pmml.MiningFunctiongetMiningFunction()Gets the type of theModel.StringgetSummary()Gets a short description of theModel.Evaluatorverify()Verifies the model.-
Methods inherited from interface org.jpmml.evaluator.HasInputFields
getActiveFields, getInputFields, getResidualFields, getSupplementaryFields
-
Methods inherited from interface org.jpmml.evaluator.HasResultFields
getOutputFields, getTargetFields
-
-
-
-
Field Detail
-
DEFAULT_TARGET_NAME
static final String DEFAULT_TARGET_NAME
The name of the default target field.
-
-
Method Detail
-
getSummary
String getSummary()
Gets a short description of the
Model.
-
getMiningFunction
org.dmg.pmml.MiningFunction getMiningFunction()
Gets the type of the
Model.
-
verify
Evaluator verify()
Verifies the model.
- Throws:
EvaluationException- If the verification fails.org.jpmml.model.MarkupException
-
evaluate
Map<String,?> evaluate(Map<String,?> arguments)
Evaluates the model with the specified arguments.
- Parameters:
arguments- Map ofinput fieldvalues.- Returns:
- Map of
target fieldandoutput fieldvalues. 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 ofComputablethat 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 bynull. - Throws:
EvaluationException- If the evaluation fails.org.jpmml.model.MarkupException- See Also:
Computable
-
-