This tutorial show how to apply an example classification model in AdvancedMiner. All the quoted names are example names of created objects.
To apply a model, it is required to:
Assumption: in the following example, it is assumed that the user has only a single model object in the MR repositiory, built during a certain model building process.
During the model applying process, the following MR objects are used:
Model applying task consists of the following steps:
If all the required objects were set up correctly, then after executing MiningApplyTask an output table with two columns should appear in the database ( see the movie ).
The steps described above can be also executed in a script.
Example 7.1. ModelApplying
# MODEL APPLYING PROCESS
# -- we assume that a model named 'MODEL' has already been build and it exists in the repository
# step 1 -- create and save PhysicalData in MR
# -- we choose the data for scoring: 'german_credit'
PD = PhysicalData('german_credit')
save('german_credit_pd',PD)
# step 2 -- create and save PhysicalData in MR
# -- we set a new name for the apply output table
PD = PhysicalData('apply_results')
save('apply_results_pd',PD)
# step 3 -- create MiningApplyTask
# -- we define that we are going to apply a model
MAT = MiningApplyTask()
# step 3a -- MiningApplyTask: add applyOutput -->> ClassificationApplyOutput
# -- we choose the type of output information: in this case for a classification model
CAO = ClassificationApplyOutput()
# step 3a-i-- MiningApplyTask -> ClassificationApplyOutput -> item: add element -->> ClassificationCategoryItem
# -- we define the output variable 'score' as the probability for the category 'bad'
CCI_score = ClassificationCategoryItem('score' , ClassificationOutputType.probability , 'bad')
CAO.item.add ( CCI_score )
# conect ClassificationApplyOutput to MiningApplyTask
MAT.setApplyOutput(CAO)
# step 3b -- MiningApplyTask: add model
# -- we choose the model to apply
MAT.setModelName('MODEL')
# step 3c -- MiningApplyTask: add sourceData
# -- we choose the data for scoring
MAT.setSourceDataName('german_credit_pd')
# step 3d -- MiningApplyTask: add targetData
# -- we choose the output data
MAT.setTargetDataName('apply_results_pd')
# step 3e -- MiningApplyTask -> directMapping: add element
# -- we define an output variable named 'real_target_value' as a copy of the 'Class' variable from input data
ASI_real_target_value = ApplySourceItem('Class','real_target_value')
MAT.directMapping.add( ASI_real_target_value )
# steps 3,3a,3a-1,3b,3c,3d,3e -- save MiningApplyTask in MR
save('MiningApplyTask',MAT)
# step 4 -- execute task 'MiningApplyTask'
execute('MiningApplyTask')
print "Done..."
Output:
Done...