source: orange/orange/doc/reference/cb-stopcriteria.py @ 526:fe2d65da2b2a

Revision 526:fe2d65da2b2a, 960 bytes checked in by janezd <janez.demsar@…>, 10 years ago (diff)
  • moved documentation from a separate module to this one
Line 
1# Description: Shows how to derive a Python class from orange.TreeStopCriteria
2# Category:    classification, callbacks to Python
3# Classes:     TreeStopCriteria
4# Uses:        lenses
5# Referenced:  callbacks.htm
6
7import orange, orngMisc, orngTree
8
9data = orange.ExampleTable("lenses")
10
11from random import randint, seed
12seed(0)
13
14defStop = orange.TreeStopCriteria()
15treeLearner = orange.TreeLearner()
16treeLearner.stop = lambda exs, wID, cont: defStop(exs, wID, cont) or randint(1, 5)==1
17
18print "\n\nTree build with stop criteria as a function"
19tree = treeLearner(data)
20orngTree.printTxt(tree)
21
22class StoppingCriterion_random(orange.TreeStopCriteria):
23  def __call__(self, gen, weightID, contingency):
24    return orange.TreeStopCriteria.__call__(self, gen, weightID, contingency) \
25           or randint(1, 5)==1
26
27print "\n\nTree build with stop criteria as a class"
28treeLearner.stop = StoppingCriterion_random()
29tree = treeLearner(data)
30orngTree.printTxt(tree)
Note: See TracBrowser for help on using the repository browser.