source: orange/Orange/doc/reference/transformvalue-d2c.py @ 9671:a7b056375472

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

Moved orange to Orange (part 2)

Line 
1# Description: Shows how to use value transformers
2# Category:    preprocessing
3# Classes:     TransformValue, Continuous2Discrete, Discrete2Continuous, MapIntValue
4# Uses:       
5# Referenced:
6
7import orange
8
9data = orange.ExampleTable("monk1")
10
11e = data.domain["e"]
12
13e1 = orange.FloatVariable("e=1")
14e1.getValueFrom = orange.ClassifierFromVar(whichVar = e)
15e1.getValueFrom.transformer = orange.Discrete2Continuous()
16e1.getValueFrom.transformer.value = int(orange.Value(e, "1"))
17
18e10 = orange.FloatVariable("e=1")
19e10.getValueFrom = orange.ClassifierFromVar(whichVar = e)
20e10.getValueFrom.transformer = orange.Discrete2Continuous()
21e10.getValueFrom.transformer.value = int(orange.Value(e, "1"))
22e10.getValueFrom.transformer.zeroBased = False
23
24e01 = orange.FloatVariable("e=1")
25e01.getValueFrom = orange.ClassifierFromVar(whichVar = e)
26transformer = e01.getValueFrom.transformer = orange.Discrete2Continuous()
27transformer.value = int(orange.Value(e, "1"))
28transformer.zeroBased = False
29transformer.invert = True
30
31
32newDomain = orange.Domain([e, e1, e10, e01], data.domain.classVar)
33newData = orange.ExampleTable(newDomain, data)
34for ex in newData[:10]:
35    print ex
36print "\n\n"
37
38attributes = [e]
39for v in e.values:
40    newattr = orange.FloatVariable("e=%s" % v)
41    newattr.getValueFrom = orange.ClassifierFromVar(whichVar = e)
42    newattr.getValueFrom.transformer = orange.Discrete2Continuous()
43    newattr.getValueFrom.transformer.value = int(orange.Value(e, v))
44    attributes.append(newattr)
45
46newDomain = orange.Domain(attributes, data.domain.classVar)
47newData = orange.ExampleTable(newDomain, data)
48for ex in newData[:10]:
49    print ex
Note: See TracBrowser for help on using the repository browser.