Example

The following script presents the abilities of the Bivariate Probit module in AdvancedMiner. Please note that this script does not include the data required to run the script in AdvancedMiner Client. The full source with the data can be found in the Examples appendix.

Example 29.1. Bivariate Probit

if not tableExists('biv_credit'):
 raise "Table 'biv_credit' does not exists. Please run Appendix Example for Bivariate"

pd = PhysicalData('biv_credit')
save('biv_pd', pd)

ld  = LogicalData(pd)
save('biv_ld',ld)

fs = BivariateFunctionSettings()
fs.setLogicalData(ld)


target = ['good','Accepted_los']

active1 = ['checking','duration']
active2 = ['history','purpose','savings']
active = ['employed']


as = BivariateProbitSettings()

vss = VariableSelectionSettings()
vss.variableSelectionMethod = VariableSelectionMethod.forward
vss.modelEntryLevel = 0.05

as.logisticPreselection = TRUE
as.randomization = TRUE

opt = OptimizationAlgorithmSettings()
opt.convergenceCriterion = ConvergenceCriterion.likelihood
opt.convergenceThreshold = 0.01
opt.iterMax = 20

fs.set1stTargetPositiveCategory('true')
fs.set2ndTargetPositiveCategory('true')

as.optimizationAlgorithmSettings = opt
as.variableSelectionSettings = vss
fs.algorithmSettings = as


us = fs.getAttributeUsageSet()
usages = us.getAttributes()
for i in range(0,usages.size()):
    usage = usages.get(i)
    usage.setUsage(UsageOption.inactive)
for attr in active:
    us.getAttribute(attr).setUsage(UsageOption.active)
for attr in active1:
    us.getAttribute(attr).setUsage(BivariateUsageOption.active1)
for attr in active2:
    us.getAttribute(attr).setUsage(BivariateUsageOption.active2)

us.getAttribute(target[0]).setUsage(UsageOption.target)
us.getAttribute(target[1]).setUsage(BivariateUsageOption.target2)

save('biv_fs', fs)

bt = MiningBuildTask('biv_pd', 'biv_fs', None)

def buildSequentially(fromSeed, tillSeed):
    for i in range(fromSeed,tillSeed):
        if i > 0:
            bt.inputModelName = 'seed%i' % (i-1)
        bt.modelName = 'seed%i' % i
        save('biv_bt', bt)
        execute('biv_bt')
        model = load('seed%i' % i)
        lf = model.getLikelihoodFunction()
        beta = lf.getSignatureBeta()
        print "\nbivariate seed model %i beta:" % i
        print "correlation (RO) = %.4f"% beta[2]

buildSequentially(0,4)

Output:

bivariate seed model 0 beta:
correlation (RO) = -0.9059

bivariate seed model 1 beta:
correlation (RO) = -0.9059

bivariate seed model 2 beta:
correlation (RO) = -0.9059

bivariate seed model 3 beta:
correlation (RO) = -0.9059