Class WekaScoringModel

java.lang.Object
org.pentaho.di.scoring.WekaScoringModel
All Implemented Interfaces:
Serializable

public abstract class WekaScoringModel extends Object implements Serializable
Abstract wrapper class for a Weka model. Provides a unified interface to obtaining predictions. Subclasses ( WekaScoringClassifer and WekaScoringClusterer) encapsulate the actual weka models.
Version:
1.0
Author:
Mark Hall (mhall{[at]}pentaho.org)
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new WekaScoringModel instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract double
    classifyInstance(weka.core.Instance inst)
    Return a classification.
    abstract double[]
    classifyInstances(weka.core.Instances insts)
    Batch scoring method.
    Static factory method to create an instance of an appropriate subclass of WekaScoringModel given a Weka model.
    abstract double[]
    distributionForInstance(weka.core.Instance inst)
    Return a probability distribution (over classes or clusters).
    abstract double[][]
    distributionsForInstances(weka.core.Instances insts)
    Batch scoring method.
    void
    Tell the model that this scoring run is finished.
    weka.core.Instances
    Get the header of the Instances that was used build this Weka model
    abstract Object
    Get the weka model
    abstract boolean
    Returns true if the encapsulated Weka model can produce predictions in a batch.
    abstract boolean
    Returns true if the encapsulated Weka model is a supervised model (i.e.
    abstract boolean
    Returns true if the encapsulated Weka model can be updated incrementally in an instance by instance fashion.
    void
    setHeader(weka.core.Instances header)
    Set the Instances header
    void
    setLog(org.pentaho.di.core.logging.LogChannelInterface log)
    Set the log to pass on to the model.
    abstract void
    Set the weka model
    abstract boolean
    update(weka.core.Instance inst)
    Update (if possible) a model with the supplied Instance

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WekaScoringModel

      public WekaScoringModel(Object model)
      Creates a new WekaScoringModel instance.
      Parameters:
      model - the actual Weka model to enacpsulate
  • Method Details

    • setLog

      public void setLog(org.pentaho.di.core.logging.LogChannelInterface log)
      Set the log to pass on to the model. Only PMML models require logging.
      Parameters:
      log - the log to use
    • setHeader

      public void setHeader(weka.core.Instances header)
      Set the Instances header
      Parameters:
      header - an Instances value
    • getHeader

      public weka.core.Instances getHeader()
      Get the header of the Instances that was used build this Weka model
      Returns:
      an Instances value
    • done

      public void done()
      Tell the model that this scoring run is finished.
    • setModel

      public abstract void setModel(Object model)
      Set the weka model
      Parameters:
      model - the Weka model
    • getModel

      public abstract Object getModel()
      Get the weka model
      Returns:
      the Weka model as an object
    • classifyInstance

      public abstract double classifyInstance(weka.core.Instance inst) throws Exception
      Return a classification. What this represents depends on the implementing sub-class. It could be the index of a class-value, a numeric value or a cluster number for example.
      Parameters:
      inst - the Instance to be classified (predicted)
      Returns:
      the prediction
      Throws:
      Exception - if an error occurs
    • distributionForInstance

      public abstract double[] distributionForInstance(weka.core.Instance inst) throws Exception
      Return a probability distribution (over classes or clusters).
      Parameters:
      inst - the Instance to be predicted
      Returns:
      a probability distribution
      Throws:
      Exception - if an error occurs
    • classifyInstances

      public abstract double[] classifyInstances(weka.core.Instances insts) throws Exception
      Batch scoring method. Call isBatchPredictor() first in order to determine if the underlying model can handle batch scoring.
      Parameters:
      insts - the instances to score
      Returns:
      an array of predictions
      Throws:
      Exception - if a problem occurs
    • distributionsForInstances

      public abstract double[][] distributionsForInstances(weka.core.Instances insts) throws Exception
      Batch scoring method. Call isBatchPredictor() first in order to determine if the underlying model can handle batch scoring.
      Parameters:
      insts - the instances to score
      Returns:
      an array of probability distributions, one for each instance
      Throws:
      Exception - if a problem occurs
    • isSupervisedLearningModel

      public abstract boolean isSupervisedLearningModel()
      Returns true if the encapsulated Weka model is a supervised model (i.e. has been built to predict a single target in the data).
      Returns:
      true if the encapsulated Weka model is a supervised model
    • isUpdateableModel

      public abstract boolean isUpdateableModel()
      Returns true if the encapsulated Weka model can be updated incrementally in an instance by instance fashion.
      Returns:
      true if the encapsulated Weka model is incremental model
    • isBatchPredictor

      public abstract boolean isBatchPredictor()
      Returns true if the encapsulated Weka model can produce predictions in a batch.
      Returns:
      true if the encapsulated Weka model can produce predictions in a batch
    • update

      public abstract boolean update(weka.core.Instance inst) throws Exception
      Update (if possible) a model with the supplied Instance
      Parameters:
      inst - the Instance to update the model with
      Returns:
      true if the model was updated
      Throws:
      Exception - if an error occurs
    • createScorer

      public static WekaScoringModel createScorer(Object model) throws Exception
      Static factory method to create an instance of an appropriate subclass of WekaScoringModel given a Weka model.
      Parameters:
      model - a Weka model
      Returns:
      an appropriate WekaScoringModel for this type of Weka model
      Throws:
      Exception - if an error occurs