source: orange/Orange/testing/regression/tests_20/reference_cb-stopcriteria.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 960 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

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.