source: orange/docs/tutorial/rst/code/domain11.py @ 9374:59bac7ddd8a2

Revision 9374:59bac7ddd8a2, 898 bytes checked in by mitar, 2 years ago (diff)

Tutorial documentation structure.

Line 
1# Description: Adds two new numerical attributes to iris data set, that are, respectively, computed from two existing attributes
2# Category:    preprocessing
3# Uses:        iris
4# Classes:     Domain, FloatVariable
5# Referenced:  domain.htm
6
7import orange
8data = orange.ExampleTable('iris')
9
10sa = orange.FloatVariable("sepal area")
11sa.getValueFrom = lambda e, getWhat: e['sepal length'] * e['sepal width']
12
13pa = orange.FloatVariable("petal area")
14pa.getValueFrom = lambda e, getWhat: e['petal length'] * e['petal width']
15
16newdomain = orange.Domain(data.domain.attributes+[sa, pa, data.domain.classVar])
17newdata = data.select(newdomain)
18
19print
20for a in newdata.domain.attributes:
21  print "%13s" % a.name,
22print "%16s" % newdata.domain.classVar.name
23for i in [10,50,100,130]:
24  for a in newdata.domain.attributes:
25    print "%8s%5.2f" % (" ", newdata[i][a]),
26  print "%16s" % (newdata[i].getclass())
Note: See TracBrowser for help on using the repository browser.