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

Revision 9671:a7b056375472, 821 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
2# Category:    feature construction, constructive induction
3# Classes:     Variable
4# Uses:        monk1
5# Referenced:  Variable.htm
6
7import orange
8
9data = orange.ExampleTable("monk1")
10
11e2 = orange.EnumVariable("e2", values = ["not 1", "1"])
12
13def checkE(example, returnWhat):
14    if example["e"]=="1":
15        return orange.Value(e2, "1")
16    else:
17        return orange.Value(e2, "not 1")
18
19e2.getValueFrom = checkE
20newDomain = orange.Domain([data.domain["a"], data.domain["b"], e2, data.domain.classVar])
21newData = orange.ExampleTable(newDomain, data)
22
23dist = orange.Distribution(e2, data)
24print dist
25
26cont = orange.ContingencyAttrClass(e2, data)
27print "Class distribution when e=1:", cont["1"]
28print "Class distribution when e<>1:", cont["not 1"]
29
Note: See TracBrowser for help on using the repository browser.