com.ibm.iminer.scoring
Class RecordScorer

java.lang.Object
  |
  +--com.ibm.iminer.scoring.Scorer
        |
        +--com.ibm.iminer.scoring.RecordScorer

public class RecordScorer
extends Scorer

This Java Bean is used to perform scoring on a single data record. The record is a set of (field name, value) pairs and must be defined by the user. The computed result can be accessed through a set of getXXX() methods.
Before calling the score(Map) method, the following needs to be specified:


Programming example:
 // 1. Constructor
 RecordScorer recordScorer = new RecordScorer();

 try {
   // 2. Specify the resources: the used model as a pmml file
   recordScorer.openModel( "MyClusterModel.pmml" );

   // 3. Get the mining fields which are used by the model.
   String[] fields = recordScorer.getMiningFields();
 
   // 4. Associate values to the mining fields.
   //    Let "fields" contain three values, the first two of type numerical,
   //    the third of type categorical. The data type can also be checked using the
   //    methods isCategoricalField( String ) and isNumericalField( String ). 
   Hashtable record = new Hashtable();
   record.put( fields[0], new Double(10.0) );
   record.put( fields[1], new Integer(5) );
   record.put( fields[2], "male" );

   // 5. Do scoring
   recordScorer.score( record );

   // 6. Access results
   int clusterID = recordScorer.getClusterID();
   double clusterQuality = recordScorer.getClusterQuality();
 } catch ( Exception e ) {
      e.printStackTrace();
 }
 


Fields inherited from class com.ibm.iminer.scoring.Scorer
CLASSIFICATION_TYPE, CLUSTER_ID, CLUSTER_QUALITY, CLUSTER_SCORE, CLUSTERING_TYPE, CONFIDENCE, PREDICTED_CLASS, PREDICTED_VALUE, RBF_REGION_ID, REGRESSION_TYPE, UNDEFINED_TYPE
 
Constructor Summary
RecordScorer()
          Default constructor.
RecordScorer(java.sql.Connection connection, java.lang.String table, java.lang.String keyColumn, java.lang.String modelColumn, java.lang.String modelKey)
          Initializes the actual RecordScorer with the mining model that is used for scoring.
RecordScorer(java.lang.String pathname)
          Initializes the actual RecordScorer with the mining model that is used for scoring.
 
Method Summary
 int getClusterID()
          Returns the cluster ID.
 double getClusterQuality()
          Returns the cluster quality.
 double getClusterScore()
          Returns the cluster score.
 double getConfidence()
          Returns the confidence.
 java.lang.String getPredictedClass()
          Returns the class label.
 double getPredictedValue()
          Returns the predicted value.
 int getRBFRegionID()
          Returns the RBF region ID.
 void openModel(java.sql.Connection connection, java.lang.String table, java.lang.String keyColumn, java.lang.String modelColumn, java.lang.String modelKey)
          Sets the mining model used for scoring.
 void openModel(java.lang.String modelFile)
          Sets the mining model used for scoring.
 void score(java.util.Map record)
          Scores a single record.
 void setModelFile(java.lang.String modelFile)
          Deprecated.  
 
Methods inherited from class com.ibm.iminer.scoring.Scorer
getCategoricalFields, getFieldNames, getModelType, getNumericalFields, getResultIdentifiers, isCategoricalField, isField, isNumericalField
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordScorer

public RecordScorer()
Default constructor. Does basic initializations.

RecordScorer

public RecordScorer(java.lang.String pathname)
             throws ModelException
Initializes the actual RecordScorer with the mining model that is used for scoring. The mining model is read from a file.
Parameters:
pathname - the path of the file that contains the mining model in PMML format

RecordScorer

public RecordScorer(java.sql.Connection connection,
                    java.lang.String table,
                    java.lang.String keyColumn,
                    java.lang.String modelColumn,
                    java.lang.String modelKey)
             throws ModelException,
                    java.sql.SQLException
Initializes the actual RecordScorer with the mining model that is used for scoring. The mining model is read from the database.
Parameters:
connection - JDBC connection used to access the database
table - Name of the table containing the model. The table can be qualified by a schema name.
keyColumn - This column contains a key that identifies the row of the table that contains the model. The key must be a character string.
modelColumn - This column contains the model (as BLOB)
modelKey - The key used to identify the model in the table.
Method Detail

getConfidence

public double getConfidence()
                     throws ResultException
Returns the confidence.
Returns:
the confidence. The value Double.NaN indicates, that the confidence couldn't be computed by the scoring algorithm.
Throws:
ResultException - thrown if the CONFIDENCE is not computed due to a model type not equal to Scorer.CLASSIFICATION_TYPE.

getClusterID

public int getClusterID()
                 throws ResultException
Returns the cluster ID.
Returns:
the cluster ID. The value -1 indicates, that the cluster number couldn't be computed by the scoring algorithm (this is the case, before calling the score( Map ) method).
Throws:
ResultException - thrown if the CLUSTER_ID is not computed due to a model type not equal to Scorer.CLUSTERING_TYPE.

getClusterQuality

public double getClusterQuality()
                         throws ResultException
Returns the cluster quality.
Returns:
the cluster quality. The value Double.NaN indicates, that the cluster quality couldn't be computed by the scoring algorithm.
Throws:
ResultException - thrown if the CLUSTER_QUALITY is not computed due to a model type not equal to Scorer.CLUSTERING_TYPE.

getClusterScore

public double getClusterScore()
                       throws ResultException
Returns the cluster score.
Returns:
the cluster score. The value Double.NaN indicates, that the cluster score couldn't be computed by the scoring algorithm.
Throws:
ResultException - thrown if the CLUSTER_SCORE is not computed due to a model type not equal to Scorer.CLUSTERING_TYPE.

getPredictedClass

public java.lang.String getPredictedClass()
                                   throws ResultException
Returns the class label.
Returns:
the class label. The value Double.NaN indicates, that the class label couldn't be computed by the scoring algorithm.
Throws:
ResultException - thrown if the PREDICTED_CLASS is not computed by scoring due to a model type that is not equal to Scorer.CLASSIFICATION_TYPE.

getPredictedValue

public double getPredictedValue()
                         throws ResultException
Returns the predicted value.
Returns:
the predicted value, if enabled for computation. The value Double.NaN indicates, that the predicted value couldn't be computed by the scoring algorithm.
Throws:
ResultException - thrown if the PREDICTED_VALUE is not computed by scoring due to a model type that is not equal to Scorer.REGRESSION_TYPE.

getRBFRegionID

public int getRBFRegionID()
                   throws ResultException
Returns the RBF region ID.
Returns:
the RBF region ID, if enabled for computation. The value -1 indicates, that value couldn't be computed by the scoring algorithm.
Throws:
ResultException - thrown if the RBF_REGION_ID is not computed by scoring due to a model type that is not equal to Scorer.REGRESSION_TYPE.

openModel

public void openModel(java.lang.String modelFile)
               throws ModelException
Sets the mining model used for scoring. The model is read from the file specified by the input parameter. If modelFile is null or "", the model is not set and the previous set model remains unchanged.
Parameters:
modelFile - the path of the file that contains the mining model in PMML format
Throws:
ModelException - thrown if something is wrong with the supplied input parameter modelFile, e.g. the specified file is not found or unspecified, an IO error occured, the specified file is not in the expected PMML format;

openModel

public void openModel(java.sql.Connection connection,
                      java.lang.String table,
                      java.lang.String keyColumn,
                      java.lang.String modelColumn,
                      java.lang.String modelKey)
               throws ModelException,
                      java.sql.SQLException
Sets the mining model used for scoring. The model is read from a database table specified by the input parameters. If one of the input parameters is null or "", the model is not set and the previous set model remains unchanged.
Parameters:
connection - JDBC connection used to access the database
table - Name of the table containing the model. The table can be qualified by a schema name.
keyColumn - This column contains a key that identifies the row of the table that contains the model. The key must be a character string.
modelColumn - This column contains the model (as BLOB)
modelKey - The key used to identify the model in the table.

setModelFile

public void setModelFile(java.lang.String modelFile)
                  throws ModelException
Deprecated.  

Sets the mining model used for scoring. The model is read from the file specified by the input parameter.
Parameters:
modelFile - the path of the file that contains the mining model in PMML format

score

public void score(java.util.Map record)
           throws RecordException,
                  ModelException
Scores a single record. The record is specified by the supplied input parameter as follows: record contains (key, value) pairs, whereat the keys are the names of the mining fields, which are used by the mining model for the scoring computation, and the values are the values of these mining fields in the actual record. Field names in the Map which are unknown for the mining model, are ignored. The following must hold for a valid record: categorical fields must have String objects associated as values, and numerical fields must have values associated to it, which can be casted to Double.
Before calling this method, a modelFile must be set and the loadModel() must be called explicitly.
Parameters:
record - The record to be scored
Throws:
RecordException - thrown if the supplied input parameter record does not fit to the loaded mining model.
ModelException - thrown if no mining model was loaded yet


Record Scorer