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 Model.

    Building and verifying an Evaluator instance
    
     EvaluatorBuilder evaluatorBuilder = new LoadingModelEvaluatorBuilder()
       .load(new File("model.pmml"));
     Evaluator evaluator = evaluatorBuilder.build();
     evaluator.verify();
     
    Preparing arguments
    Transforming an user-supplied map of arguments to a known-good PMML map of 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
    Retrieving the values of 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
    A code block that does exception-prone work should be surrounded with two levels of try-catch statements. The inner try statement should catch EvaluationException instances that indicate "local" problems, which are related to individual data records. The outer try statement should catch MarkupException instances 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 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.

      • evaluate

        Map<String,​?> evaluate​(Map<String,​?> arguments)

        Evaluates the model with the specified arguments.

        Parameters:
        arguments - Map of input field values.
        Returns:
        Map of 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.
        Throws:
        EvaluationException - If the evaluation fails.
        org.jpmml.model.MarkupException
        See Also:
        Computable