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

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

Moved orange to Orange (part 2)

Line 
1# Description: Shows how to use orange.Domain for example conversion. Also shows how to add meta-attributes to domain descriptors and use them.
2# Category:    basic classes, meta-attributes
3# Classes:     Domain
4# Uses:        monk1
5# Referenced:  Domain.htm
6
7import orange
8
9data = orange.ExampleTable("monk1")
10
11d2 = orange.Domain(["a", "b", "e", "y"], data.domain)
12
13example = data[55]
14print example
15
16example2 = d2(example)
17print example2
18
19example2 = orange.Example(d2, example)
20print example2
21
22data2 = orange.ExampleTable(d2, data)
23print data2[55]
24
25d2.addmeta(orange.newmetaid(), orange.FloatVariable("w"))
26data2 = orange.ExampleTable(d2, data)
27print data2[55]
28
29misses = orange.FloatVariable("misses")
30id = orange.newmetaid()
31data.domain.addmeta(id, misses)
32print data[55]
33
34print data.domain.hasmeta(id)
35print data.domain.hasmeta(id-1)
36
37for example in data:
38    example[misses] = 0
39
40classifier = orange.BayesLearner(data)
41for example in data:
42    if example.getclass() != classifier(example):
43        example[misses] += 1
44
45for example in data:
46    print example
47
48data = orange.ExampleTable("monk1")
49domain = data.domain
50d2 = orange.Domain(["a", "b", "e", "y"], domain)
51for attr in ["c", "d", "f"]:
52    d2.addmeta(orange.newmetaid(), domain[attr])
53d2.addmeta(orange.newmetaid(), orange.EnumVariable("X"))
54data2 = orange.ExampleTable(d2, data)
55
56print data[55]
57print data2[55]
58
59ido = -99
60idr = -100
61data.domain.addmeta(idr, orange.FloatVariable("required"), False)
62data.domain.addmeta(ido, orange.FloatVariable("optional"), True)
63print data.domain.isOptionalMeta(ido)
64print data.domain.isOptionalMeta(idr)
65print data.domain.getmetas()
66print data.domain.getmetas(True)
67print data.domain.getmetas(False)
Note: See TracBrowser for help on using the repository browser.