Building a Scoring Application Using a Scoring Routine

How to:

A scoring application enables you to score new data using an RStat scoring routine. Once deployed, scoring routines become user-defined functions (also known as FUSELIB routines). These routines can be used to apply the model formula to new data within any DEFINE or COMPUTE expression. You can define the expression containing the RStat scoring routine using the Function Arguments dialog box or by manually entering the WebFOCUS syntax.

In this example, we have generated and deployed a scoring routine based on a binary Decision Tree Model. Scoring routines can be generated for the following models: Decision Tree (numeric, binary and multinomial), Regression (linear, general linear, poisson, logistic, and multinomial) and Clustering (KMeans, Ewkm, and Hierarchical), NNet, Boost, Random Forest, Survival, Market Basket Analysis, and Association Rules.

RStat brings the power of predictive analytics to the operational enterprise. Any WebFOCUS application can select new data to be scored and then provide ad hoc analytics through active reports, plot the prediction on a map or graph, or support real-time decision-making through KPI dashboards and transactional process flows.


Top of page

x
Procedure: How to Score New Data With RStat Scoring Routines in App Studio
  1. Create a new procedure in the Report canvas, and select the appropriate Master File for the new applicant data set.

    You can use any data source that contains the input variables defined for the model. For the purposes of this example, use the AB_NewCustomers data file.

  2. Add the following fields to the report: ID, AGE, EDUCATION, MARITAL, GENDER, OCCUPATION, and INCOME.

  3. Right-click inside the Object Inspector, then click New Compute Virtual Field.

    The Computed Field Creator dialog box opens.

    Define the expression as the scoring function with your new data fields as the model input variables and the computed field (SCORE) as the final parameter.

    Note: Optionally, you may create a Define field. For the purposes of this example, create a Compute field.

  4. Set the field name to SCORE.
  5. Set the field format to A2.
  6. Create the field expression containing the RStat function.

    Note: You can define RStat scoring routines within a COMPUTE expression by using the Function Arguments dialog box or by creating a command using WebFOCUS syntax.

    • To build the RStat scoring expression using the Functions Arguments Dialog Box:
      1. Click the Functions button to build the scoring expression.

        Conputed Field Creator dialog box

        The Function Arguments dialog box opens and lists all available built-in functions. A list of predefined functions are grouped into categories that include Character, Data Source and Decoding, Date and Time, Format Conversion, Numeric, and System. Each of the available functions is a routine that takes input parameters and returns a value.

      2. Click Retrieve Scoring Routines to retrieve the RStat scoring routines available within the current application directory.

        If any RStat Scoring Routines are found within the current application directory, RStat Scoring Routines is added as a category and the related functions appear in the Select a function list. Once the retrieve is completed successfully, the button text changes to Refresh Scoring Routines. You can use the Refresh button to update the list of available routines if you know that the new routines have been added to the current application directory or the existing ones have changed.

        Note: If no routines are found, the button text changes to No Scoring Routines Found, the RStat Scoring Routine Category is not added to the available list, and the button is disabled.

      3. Select ab_creditscore_tree from the function drop-down list.

        The Input Parameters, Types, and Value columns appear for the function.

      4. Drag the fields to be used as input parameters from the field list displayed on the right of the Functions Arguments dialog box, or type the field names directly into the value field. For this example, click the field name from the field list and drag the field name to the value field as follows:
        • For the AGE input parameter, drag AGE into the Value field.
        • For the EDUCATION input parameter, drag EDUCATION into the Value field.
        • For the OCCUPATION input parameter, drag OCCUPATION into the Value field.
        • For the INCOME input parameter, drag INCOME into the Value field.
      5. Enter the name of the compute or define (for example, SCORE) as the format assigned to the target variable in the Target CREDIT_APPROVAL (alpha) input field.
      6. Click OK to close the Function Arguments dialog box.

        The function argument is added to the COMPUTE expression.

    • Create the RStat function by entering a command using WebFOCUS syntax:

      Enter the following command in the expression window of the Computed Field Creator dialog box:

      AB_CREDITSCORE_TREE(AGE, EDUCATION, OCCUPATION, INCOME, SCORE)

    The COMPUTE expression appears as follows.

    Conputed Field Creator dialog box

  7. Click New to create a second Compute field to display YES if the score is 1 or No if the score is 0:
    APPROVED/A3 = IF SCORE EQ '1' THEN 'YES' ELSE 'NO';

    The Compute tool generates the following expression:

    COMPUTE SCORE/A2 = ab_creditscore_tree(AB_NEWCUSTOMERS.SEG_01.AGE, AB_NEWCUSTOMERS.SEG_01.EDUCATION,
         AB_NEWCUSTOMERS.SEG_01.MARITAL, AB_NEWCUSTOMERS.SEG_01.GENDER, AB_NEWCUSTOMERS.SEG_01.OCCUPATION,
         AB_NEWCUSTOMERS.SEG_01.INCOME, 'A2');
    COMPUTE APPROVED/A3 = IF SCORE EQ '1' THEN 'YES' ELSE 'NO';
  8. Click OK to close the Computed Field Creator dialog box.
  9. Run the procedure to see the predicted values.

Top of page

x
Procedure: How to Score New Data With RStat Scoring Routines in Developer Studio

You can use RStat scoring routines to apply the model formula to new data within any expression within a COMPUTE or DEFINE.

The calling syntax of a scoring routine is determined based on the input and target variables defined within the model. A sample routine call might look like:

SCORING_ROUTINE(INPUT_1, INPUT_2, INPUT_3, INPUT_4, INPUT_5, INPUT_6, TARGET)

For example:

AB_CREDITSCORE_TREE(AGE, EDUCATION, MARITAL, GENDER, OCCUPATION, INCOME, SCORE)
  1. Create a new procedure in Report Painter and select the appropriate Master File for the new applicant data set.

    You can use any data source that contains the input variables defined for the model. For the purposes of this example, use the AB_NewCustomers data file.

  2. Add the following fields to the report: ID, AGE, EDUCATION, MARITAL, GENDER, OCCUPATION, and INCOME.

    New Procedure window

  3. Create a new Compute field.

    Define the expression as the scoring function with your new data fields as the model input variables and the computed field (SCORE) as the final parameter.

    Note: Optionally, you may create a Define field. For the purposes of this example, create a Compute field.

  4. Set the field name to SCORE.
  5. Set the field format to A2.
  6. Create the field expression containing the RStat function.

    Note: You can define RStat scoring routines within a COMPUTE expression by using the Function Arguments dialog box or by creating a command using WebFOCUS syntax.

    • To build the RStat scoring expression using the Functions Arguments Dialog Box:
      1. Click the Functions button to build the scoring expression, as shown in the following image.

        Functions button

        The Function Arguments dialog box opens and lists all available built-in functions. A list of predefined functions are grouped into categories that include Character, Data Source and Decoding, Date and Time, Format Conversion, Numeric, and System. Each of the available functions is a routine that takes input parameters and returns a value.

        Function Arguments dialog box

      2. Click Retrieve Scoring Routines to retrieve the RStat scoring routines available within the current application directory.

        If any RStat Scoring Routines are found within the current application directory, RStat Scoring Routines is added as a category and the related functions appear in the Select a function list. Once the retrieve is completed successfully, the button text changes to Refresh Scoring Routines. You can use the Refresh button to update the list of available routines if you know that the new routines have been added to the current application directory or the existing ones have changed.

        Note: If no routines are found, the button text changes to No Scoring Routines Found, the RStat Scoring Routine Category is not added to the available list, and the button is disabled.

      3. Select ab_creditscore_tree from the function drop-down list, as shown in the following image.

        The Input Parameters, Types, and Value columns appear for the function.

      4. Drag the fields to be used as input parameters from the field list displayed on the right of the Functions Arguments dialog box, or type the field names directly into the value field. For this example, click the field name from the field list and drag the field name to the value field as follows:
        • For the AGE input parameter, drag AGE into the Value field.
        • For the EDUCATION input parameter, drag EDUCATION into the Value field.
        • For the OCCUPATION input parameter, drag OCCUPATION into the Value field.
        • For the INCOME input parameter, drag INCOME into the Value field.
      5. Enter the name of the compute or define (for example, SCORE) as the format assigned to the target variable in the Target CREDIT_APPROVAL (alpha) input field.

        The following image shows the Function Arguments dialog box with these options.

        Function Arguments dialog box

      6. Click OK to close the Function Arguments dialog box.

        The function argument is added to the COMPUTE expression.

    • Create the RStat function by entering a command using WebFOCUS syntax:

      Enter the following command in the expression window of the Computes tab:

      AB_CREDITSCORE_TREE(AGE, EDUCATION, OCCUPATION, INCOME, SCORE)

    The COMPUTE expression appears as follows.

    COMPUTE tab

  7. Click New to create a second Compute field to display YES if the score is 1 or No if the score is 0:
    APPROVED/A3 = IF SCORE EQ '1' THEN 'YES' ELSE 'NO';

    The Compute tool generates the following expression:

    COMPUTE SCORE/A2 = ab_creditscore_tree(AB_NEWCUSTOMERS.SEG_01.AGE, AB_NEWCUSTOMERS.SEG_01.EDUCATION,
         AB_NEWCUSTOMERS.SEG_01.MARITAL, AB_NEWCUSTOMERS.SEG_01.GENDER, AB_NEWCUSTOMERS.SEG_01.OCCUPATION,
         AB_NEWCUSTOMERS.SEG_01.INCOME, 'A2');
    COMPUTE APPROVED/A3 = IF SCORE EQ '1' THEN 'YES' ELSE 'NO';
  8. Click OK to close the Report Options dialog box.
  9. Run the procedure to see the predicted values.

    Procedure output dialog box


WebFOCUS