| 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 | |
|---|
| 7 | import orange |
|---|
| 8 | data = orange.ExampleTable('iris') |
|---|
| 9 | |
|---|
| 10 | sa = orange.FloatVariable("sepal area") |
|---|
| 11 | sa.getValueFrom = lambda e, getWhat: e['sepal length'] * e['sepal width'] |
|---|
| 12 | |
|---|
| 13 | pa = orange.FloatVariable("petal area") |
|---|
| 14 | pa.getValueFrom = lambda e, getWhat: e['petal length'] * e['petal width'] |
|---|
| 15 | |
|---|
| 16 | newdomain = orange.Domain(data.domain.attributes+[sa, pa, data.domain.classVar]) |
|---|
| 17 | newdata = data.select(newdomain) |
|---|
| 18 | |
|---|
| 19 | print |
|---|
| 20 | for a in newdata.domain.attributes: |
|---|
| 21 | print "%13s" % a.name, |
|---|
| 22 | print "%16s" % newdata.domain.classVar.name |
|---|
| 23 | for 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.