Introduction
------------

This file introduces 7 new prediction user defined functions (UDF) - each in 
two versions - that are implemented in PL/SQL. The prediction UDFs are 
wrapping SQL SELECT statements including IM Scoring UDFs that are applying 
a model to a data record and then extract one result value from the result, 
e.g. cluster id.



Installation
------------
There is no special installation procedure, because the functions are 
automatically installed when idm_setup is executed for the database.



Example
-------
A simple query using one of the new prediction UDFs could look like:

  SELECT B.AGE,
         IDMMX.PredictClusterID('DemoBanking',
           IDMTY.DM_ApplRow(
             IDMTY.DM_ApplColumn('TYPE', B.TYPE, NULL),
             IDMTY.DM_ApplColumn('AGE', NULL, B.AGE),
             IDMTY.DM_ApplColumn('SIBLINGS', NULL, B.SIBLINGS),
             IDMTY.DM_ApplColumn('INCOME', NULL, B.INCOME))) AS ClusterID
    FROM BANKING_SCORING B;

The query refers to a table BANKING_SCORING, which contains information about
the customers of a bank. For each customer, the prediction function computes 
a cluster ID. This prediction is implemented by the UDF PredictClusterID.
The first argument 'DemoBanking' is the name of a mining model.
The input data to this UDF is constructed by DM_ApplRow/DM_ApplColumn.
Note: If you want to execute the above example, then first create the
model sample tables, then load the BANKING_SCORING table by executing the 
script banking_import.sql and then import the model by executing the script 
banking_insert.sql. To this end, call SQL*Plus (from the samples directory) 
and enter:

SQL> @idm_create_demotab
SQL> @banking_import
SQL> @banking_insert

You could also execute a provided sample script PredictFunctions-sample.sql 
by calling

SQL> @PredictFunctions-sample

after you have executed the scripts idm_create_demotab.sql,
banking_import.sql, and banking_insert.sql.

The result table contains simple values like

                 AGE    CLUSTERID
       ------------- ------------
               24.06            1
                 0.4            2
                  30            3


The UDF PredictClusterID( Model, Values ) returns a NUMBER.
The parameter Model refers to the name of the model.
If you have installed IM Scoring without any change in the file 
idm_setvars.sql, then the model must be contained in the table 
<Your schema>.ClusterModels, which has a column MODEL for the model and 
a column MODELNAME which contained the name of the model.

DM_ApplRow/DM_ApplColumn define the input data record for PredictClusterID.


Explanation
-----------

The templates for the new predictions UDFs are

a)     IDMMX.PredictSomeValue(ModelName, InputDataAsXMLString)
b)     IDMMX.PredictSomeValue(ModelName, InputDataAsApplRowObject)

The first argument is the name of a mining model.
In case a) the second argument is an XML string (VARCHAR2) that can either be 
constructed manually or by nested calls of IDMMX.DM_applData functions.
In case b) the second argument is an IDMTY.DM_ApplRow object that contains the
input data in its IDMTY.DM_ApplColumn elements.

These are the new prediction functions:

  IDMMX.PredictClusterID(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusterID(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

  IDMMX.PredictClusConf(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusConf(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

  IDMMX.PredictClusScore(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusScore(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

  IDMMX.PredictClusQuality(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusQuality(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

  IDMMX.PredictClass(ModelName, InputDataAsXMLString) RETURNS VARCHAR2
  IDMMX.PredictClass(ModelName, InputDataAsApplRowObject) RETURNS VARCHAR2

  IDMMX.PredictClassConf(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClassConf(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

  IDMMX.PredictValue(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictValue(ModelName, InputDataAsApplRowObject) RETURNS NUMBER


The first three prediction functions are based on a mining technique called 
clustering. The functions PredictClass and PredictClassConf  are based on the 
classification technique. The function PredictValue is based on numeric value 
prediction.



Function reference
------------------


PredictClusterID

This function obtains the cluster ID from results data that is produced when
you apply a clustering model. This identifies the particular cluster in the 
clustering model that is the best match for this data.

Function syntax

  IDMMX.PredictClusterID(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusterID(ModelName, InputDataAsApplRowObject) RETURNS NUMBER
 
Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictClusterID returns the cluster ID as data type NUMBER


---------------

PredictClusConf

This function obtains the confidence from results data that is produced
when you apply a clustering model. This is a value between 0.0 and 1.0 that
expresses the probability that the predicted cluster is the best match against
the other clusters.

Function syntax

  IDMMX.PredictClusConf(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusConf(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictClusConf returns the clustering score as data type NUMBER.


---------------

PredictClusScore

This function obtains the clustering score from results data that is produced
when you apply a clustering model. The score is an expression of how closely
the data matches the predicted cluster. For Demographic Clustering a score 
value close to 1.0 indicates a good match. For Neural Clustering a score value 
close to 0.0 indicates a good match. Note that the score value may indicate a 
good match even when the confidence returned by PredictClusConf is low.
This happens if the data matches another cluster that is very close to the 
first one.

Function syntax

  IDMMX.PredictClusScore(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusScore(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictClusScore returns the clustering score as data type NUMBER.


---------------

PredictClusQuality

This function returns the quality of the result for a given cluster. It measures
how good the applied record fits into the given cluster. The returned value is
between 0.0 and 1.0. A value close to 0.0 means that the record does not fit at
all in the cluster, a value close to 1.0 means that the record fits very well
in the given cluster. The quality measurement depends on the algorithm used
to score the record, so that a direct comparison between the quality of
both clustering algorithm results is not possible.
However, both algorithms use a linear, possibly similar quality measurement 
function.

Function syntax

  IDMMX.PredictClusQuality(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClusQuality(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictClusQuality returns the clustering quality as data type NUMBER.


---------------

PredictClass

This function obtains the predicted class from results data that is produced
when you apply a classification model. This identifies, within the
model, the particular class that matches the data.

Function syntax

  IDMMX.PredictClass(ModelName, InputDataAsXMLString) RETURNS VARCHAR2
  IDMMX.PredictClass(ModelName, InputDataAsApplRowObject) RETURNS VARCHAR2

Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictClass returns the predicted class as data type VARCHAR2.


---------------

PredictClassConf

This function obtains the classification confidence value from results data that
is produced when you apply a classification model. The confidence is a value
between 0.0 and 1.0 that expresses the probability that the class is predicted
correctly.

Function syntax

  IDMMX.PredictClassConf(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictClassConf(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictClassConf returns the confidence value as data type NUMBER.


---------------

PredictValue

This function obtains the predicted value from results data that is produced 
when you apply a regression model. This value is calculated according to 
relations that are established by the model.

Function syntax

  IDMMX.PredictValue(ModelName, InputDataAsXMLString) RETURNS NUMBER
  IDMMX.PredictValue(ModelName, InputDataAsApplRowObject) RETURNS NUMBER

Function parameters

ModelName: 
  The name of a model in the default table containing clustering models.
InputDataAsXMLString: 
  A string that contains all the input arguments required by the model. The 
  string can either be produced by nested calls of IDMMX.DM_applData or 
  assembled manually.
InputDataAsApplRowObject: 
  An IDMTY.DM_ApplRow object containing the required input data in its 
  IDMTY.DM_ApplColumn elements.

PredictValue returns the predicted value as data type NUMBER.


---------------
