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

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

Tutorial documentation structure.

Line 
1# Description: Shows how to use Filter_sameValues qith options for conjunction and disjunction of conditions
2# Category:    preprocessing
3# Uses:        imports-85
4# Classes:     Preprocessor_take
5# Referenced:  domain.htm
6
7import orange
8
9def report_prob(header, data):
10  print 'Size of %s: %i instances; ' % (header, len(data)), 
11  n = 0
12  for i in data:
13    if int(i.getclass())==0:
14      n = n + 1
15  if len(data):
16    print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data))
17  else:
18    print
19
20filename = "../../datasets/adult_sample.tab"
21data = orange.ExampleTable(filename)
22report_prob('data', data)
23
24filter = orange.Preprocessor_take()
25filter.values = {data.domain["sex"]: "Male", data.domain["education"]: "Masters"}
26
27filter.conjunction = 1
28data1 = filter(data)
29report_prob('data1 (conjunction)', data1)
30
31filter.conjunction = 0
32data1 = filter(data)
33report_prob('data1 (disjunction)', data1)
34
35data2 = data.select(sex='Male', education='Masters')
36report_prob('data2 (select, conjuction)', data2)
Note: See TracBrowser for help on using the repository browser.