Chapter 1. Scoring Card Building With Model Guide

Table of Contents

Logistic regression model building
Converting the model to a scoring card

This tutorial describes how to create a scoring card based on a linear regression model using AdvancedMiner's Scoring Card module.

Before building a scoring card it is required to have a table with data available in the database. Moreover, it is assumed that the user is familiar with the QuickStart tutorial.

The presented example is based on the 'german_credit' dataset. All quoted names are example names of created objects.

The following MR objects are used during the scoring card building process with a regression model:

Figure 1.1. Schema of the scoring card building process with a regression model

Schema of the scoring card building process with a regression model

The scoring card building process with a regression model is made up of two stages: logistic regression model building stage and model to scoring card conversion stage.

Logistic regression model building

  • step 1:
    • create PhysicalData ('german_credit_pd')
    • we choose the building data: 'german_credit'

  • step 2:
    • create MiningFunctionSettings -->> ClassificationFunctionSettings ('ModelFunctionSettings')
    • we define that we are going to prepare a classification model

      • step 2a:
        • add algorithmSettings -->> LogisticRegressionSettings
        • we choose the classification algorythm: logistic regression
      • step 2b:
        • add logicalData
        • we define the logical structure of the build data using PhysicalData named 'german_credit_pd'
      • step 2c:
        • attributeUsageSet: set the target attribute
        • we choose the attribute 'Class' as target

  • step 3:
    • create MiningBuildTask ('ModelBuildTask')
    • we define the action we are going to do: model building

      • step 3a:
        • add buildData
        • we choose 'german_credit_pd' for PhysicalData of the data for model building
      • step 3b:
        • add functionSettings
        • we choose the method and algorithm settings for model building
      • step 3c:
        • add model ('MODEL')
        • we set the new output model name

  • step 4:
    • execute task 'ModelBuildTask'

If all the required objects were set up correctly, then after executing 'ModelBuildTask' a new regression model should appear in the MR repository. The user can browse model details by double-clicking the model icon (see the movie). The Figure below shows the content of the MR repository and the model created after carrying out the steps described above.

Figure 1.2. The result of ModelBuildTask

The result of ModelBuildTask

The steps described above can be also executed in a single script.

Example 1.1. Scoring card building process with regression model



#                               SCORING CARD BUILDING PROCESS WITH REGRESSION MODEL    

# BUILDING THE MODEL
# step 1 -- create and save PhysicalData in MR 
#        -- we choose the building data: 'german_credit'
PD = PhysicalData('german_credit')
save('german_credit_pd',PD)

# step 2 -- create MiningFunctionSettings -->> ClassificationFunctionSettings()
#        -- we define that we are going to prepare a classification model
MFS = ClassificationFunctionSettings()

# step 2a -- MiningFunctionSettings: add algorithmSettings -->> LogisticRegressionSettings
#         -- we choose the classification algorythm: logistic regression
MFS.setAlgorithmSettings(LogisticRegressionSettings())

# step 2b -- MiningFunctionSettings: add logicalData
#         -- we define the logical structure of the building data
MFS.setLogicalData(LogicalData(PD))

# step 2c -- MiningFunctionSettings -> attributeUsageSet: set target attribute
#         -- we choose the 'Class' attribute as the target
MFS.getAttributeUsageSet().getAttribute('Class').usage = UsageOption.target

# steps 2,2a,2b,2c -- save MiningFunctionSettings into MR
save('ModelFunctionSettings',MFS)

# step 3 -- create MiningBuildTask
#        -- we define the action we are going to do: model building
MBT = MiningBuildTask()

# step 3a -- MiningBuildTask: add buildData
#         -- we choose the data for model building
MBT.setBuildDataName('german_credit_pd')

# step 3b -- MiningBuildTask: add functionSettings
#         -- we choose the method and algorithm settings for model building
MBT.setFunctionSettingsName('ModelFunctionSettings')

# step 3c -- MiningBuildTask: add model 
#         -- we set the new output model name
MBT.setModelName('MODEL')

# steps 3,3a,3b,3c -- save MiningBuildTask into MR
save('ModelBuildTask',MBT)

# step 4 -- execute task
execute('ModelBuildTask')



# CONVERTING THE MODEL INTO A SCORING CARD
# step 1 -- create MiningFunctionSettings -->> ScoringCardSettings()
#        -- we define that we are going to prepare a scoring card
MFS = ScoringCardSettings()

# step 1a -- MiningFunctionSettings: add logicalData
#         -- we define the logical structure of the building data
MFS.setLogicalData(LogicalData(PD))

# step 1b -- MiningFunctionSettings: add regression model
#	  -- we choose the regression model we want to convert into a scoring card
MFS.setRegressionModelName('MODEL')

# step 1c -- MiningFunctionSettings -> attributeUsageSet: set target attribute
#         -- we choose the 'Class' attribute as the target
MFS.getAttributeUsageSet().getAttribute('Class').usage = UsageOption.target

# steps 1,1a,1b,1c -- save MiningFunctionSettings into MR
save('ScoringCardSettings',MFS)

# step 2 -- create MiningBuildTask
#        -- we define the action we are going to do: scoring card building
MBT = MiningBuildTask()

# step 2a -- MiningBuildTask: add buildData
#         -- we choose the data for model building
MBT.setBuildDataName('german_credit_pd')

# step 2b -- MiningBuildTask: add functionSettings
#         -- we add the settings for scoring card building
MBT.setFunctionSettingsName('ScoringCardSettings')

# step 2c -- MiningBuildTask: add model 
#         -- we set the name of the output scoring card
MBT.setModelName('CARD')

# steps 2,2a,2b,2c -- save MiningBuildTask into MR
save('ScoringCardBuildTask',MBT)

# step 3 -- execute task
execute('ScoringCardBuildTask')


print "Done..."

Output:

Done...