def test_boost(self):
     listAttr = randlist(0, 5, 10)
     listInst = [dtree.Instance(listAttr, True) for _ in xrange(100)]
     listInstFalse = random.sample(listInst, 10)
     for inst in listInstFalse:
         inst.fLabel = False
     listInstCopy = [inst.copy() for inst in listInst]
     br = dtree.boost(listInstCopy)
     dblWeightExpected = dtree.classifier_weight(0.1)
     self.assertAlmostEqual(br.listDblCferWeight[0], dblWeightExpected)
Пример #2
0
 def test_boost(self):
     listAttr = randlist(0,5,10)
     listInst = [dtree.Instance(listAttr, True) for _ in xrange(100)]
     listInstFalse = random.sample(listInst,10)
     for inst in listInstFalse:
         inst.fLabel = False
     listInstCopy = [inst.copy() for inst in listInst]
     br = dtree.boost(listInstCopy)
     dblWeightExpected = dtree.classifier_weight(0.1)
     self.assertAlmostEqual(br.listDblCferWeight[0], dblWeightExpected)
 def test_one_round_boost(self):
     fxnGen = build_consistent_generator()
     cInst = 100
     listInst = fxnGen(cInst)
     for inst in listInst:
         inst.listAttrs[0] = int(inst.fLabel)
     listInstIncorrect = random.sample(listInst, cInst / 10)
     for inst in listInstIncorrect:
         inst.fLabel = not inst.listAttrs[0]
         inst.dblWeight = 0.1
     dt, dblError, dblCferWeight = dtree.one_round_boost(listInst, 1)
     self.assertTrue(is_stump(dt))
     self.assertAlmostEqual(1.0 / 91.0, dblError)
     self.assertAlmostEqual(dtree.classifier_weight(dblError),
                            dblCferWeight)
     self.assertAlmostEqual(1.0, sum([inst.dblWeight for inst in listInst]))
Пример #4
0
 def test_one_round_boost(self):
     fxnGen = build_consistent_generator()
     cInst = 100
     listInst = fxnGen(cInst)
     for inst in listInst:
         inst.listAttrs[0] = int(inst.fLabel)
     listInstIncorrect = random.sample(listInst,cInst/10)
     for inst in listInstIncorrect:
         inst.fLabel = not inst.listAttrs[0]
         inst.dblWeight = 0.1
     dt,dblError,dblCferWeight = dtree.one_round_boost(listInst,1)
     self.assertTrue(is_stump(dt))
     self.assertAlmostEqual(1.0/91.0, dblError)
     self.assertAlmostEqual(dtree.classifier_weight(dblError),
                            dblCferWeight)
     self.assertAlmostEqual(1.0, sum([inst.dblWeight for inst in listInst]))
 def test_classifier_weight(self):
     dblError = random.random()
     dblWeight = dtree.classifier_weight(dblError)
     dblFrac = math.exp(2.0 * dblWeight)
     self.assertAlmostEqual(dblError, 1.0 / (dblFrac + 1.0))
Пример #6
0
 def test_classifier_weight(self):
     dblError = random.random()
     dblWeight = dtree.classifier_weight(dblError)
     dblFrac = math.exp(2.0*dblWeight)
     self.assertAlmostEqual(dblError, 1.0/(dblFrac + 1.0))