Class AbstractPredictor

All Implemented Interfaces:
LogicalOperator
Direct Known Subclasses:
ClusterPredictor, DecisionTreePredictor, LogisticRegressionPredictor, NaiveBayesPredictor, RegressionPredictor, SVMPredictor

public abstract class AbstractPredictor extends ExecutableOperator
Common base class for "predictor" processes. Predictors all take a PMML input, a record input and produce a record output. In addition, all predictors are parallel.
  • Constructor Details

    • AbstractPredictor

      public AbstractPredictor()
  • Method Details

    • getInput

      public final RecordPort getInput()
      The input data. Any fields specified in the PMML model must be present in the input data. Additional fields will be ignored.
      Returns:
      the input data
    • getModel

      public final PMMLPort getModel()
      The input for supplying the PMML model
      Returns:
      the input for the pmml model
    • getOutput

      public RecordPort getOutput()
      The original data with prediction appended
      Returns:
      the original data with the prediction appended
    • computeMetadata

      protected void computeMetadata(StreamingMetadataContext ctx)
      Default implementation of computeMetadata.
      1. Output type is set to input type plus predictedType
      2. Input data ordering ( if ordered ) is preserved
      3. Input data partitioning ( if partitioned ) is preserved
      Specified by:
      computeMetadata in class StreamingOperator
      Parameters:
      ctx - the context
    • stepNext

      protected final boolean stepNext()
      Steps to the next input row, returning false at end of data
      Returns:
      true if there is still more data
    • pushPrediction

      protected final void pushPrediction()
      Pushes a prediction row consisting of input fields plus predicted fields
    • execute

      protected final void execute(ExecutionContext ctx)
      Invokes execute(PMMLModel, RecordValued, ScalarSettable[]) and performs an output.pushEndOfData()
      Specified by:
      execute in class ExecutableOperator
      Parameters:
      ctx - context in which to lookup physical ports bound to logical ports
    • predictedType

      protected abstract RecordTokenType predictedType(PMMLModelSpec modelSpec)
      Given the model spec, returns the predicted type. This should not include the input type ( the input is automatically prepended to the type that is returned )
      Parameters:
      modelSpec - the model metadata
      Returns:
      the predicted type
    • execute

      protected abstract void execute(PMMLModel model, RecordValued input, ScalarSettable[] predictedFields)
      Called to perform prediction. Subclasses are expected to loop over the input by calling stepNext(). For each row of input, subclasses should first set the predicted values in the predictedFields array and then invoke pushPrediction(). Subclasses should not invoke pushEndOfData since that is automatically handled by the base class.
      Parameters:
      model - The input PMML model
      input - The input data
      predictedFields - An array of fields that reference the predicted field locations. The array positionally corresponds to the type returned by predictedType(PMMLModelSpec).