source: orange/Orange/doc/reference/variable2.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 880 bytes checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1# Description: Shows how to construct new attributes from the existing and use it seamlessly in sampling and testing
2# Category:    feature construction, constructive induction
3# Classes:     Variable, MakeRandomIndices2
4# Uses:        monk1
5# Referenced:  Variable.htm
6
7import orange, orngTree
8
9data = orange.ExampleTable("monk1")
10
11indices = orange.MakeRandomIndices2(data, p0=0.7)
12trainData = data.select(indices, 0)
13testData = data.select(indices, 1)
14
15e2 = orange.EnumVariable("e2", values = ["not 1", "1"])
16e2.getValueFrom = lambda example, returnWhat: \
17                  orange.Value(e2, example["e"]=="1")
18
19newDomain = orange.Domain([data.domain["a"], data.domain["b"], e2, data.domain.classVar])
20newTrain = orange.ExampleTable(newDomain, trainData)
21
22tree = orange.TreeLearner(newTrain)
23
24orngTree.printTxt(tree)
25
26for ex in testData[:10]:
27    print ex.getclass(), tree(ex)
28
Note: See TracBrowser for help on using the repository browser.