source: orange/orange/doc/ofb/domain12.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 1.5 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line 
1# Description: Add a new attribute price to a car data set, compute it from two existing attributes (buying, maint)
2# Category:    preprocessing
3# Uses:        car
4# Classes:     Domain, Value, getValueFrom, EnumVariable
5# Referenced:  domain.htm
6
7import orange
8data = orange.ExampleTable('../datasets/car')
9
10# add attribute price = f(buying, maint)
11# see also http://www.ailab.si/hint/car_dataset.asp
12
13priceTable={}
14priceTable['v-high:v-high'] = 'v-high'
15priceTable['high:v-high'] = 'v-high'
16priceTable['med:v-high'] = 'high'
17priceTable['low:v-high'] = 'high'
18priceTable['v-high:high'] = 'v-high'
19priceTable['high:high'] = 'high'
20priceTable['med:high'] = 'high'
21priceTable['low:high'] = 'med'
22priceTable['v-high:med'] = 'high'
23priceTable['high:med'] = 'high'
24priceTable['med:med'] = 'med'
25priceTable['low:med'] = 'low'
26priceTable['v-high:low'] = 'high'
27priceTable['high:low'] = 'high'
28priceTable['med:low'] = 'low'
29priceTable['low:low'] = 'low'
30
31def f(price, buying, maint):
32  return orange.Value(price, priceTable['%s:%s' % (buying, maint)])
33
34price = orange.EnumVariable("price", values=["v-high", "high", "med", "low"])
35price.getValueFrom = lambda e, getWhat: f(price, e['buying'], e['maint'])
36newdomain = orange.Domain(data.domain.attributes+[price, data.domain.classVar])
37newdata = data.select(newdomain)
38
39print
40for a in newdata.domain.attributes:
41  print "%10s" % a.name,
42print "%10s" % newdata.domain.classVar.name
43for i in [1,200,300,1200,1700]:
44  for a in newdata.domain.attributes:
45    print "%10s" % newdata[i][a],
46  print "%10s" % newdata[i].getclass()
Note: See TracBrowser for help on using the repository browser.