source: orange/Orange/doc/ofb/domain7.py @ 9671:a7b056375472

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

Moved orange to Orange (part 2)

Line 
1# Description: Shows how to add class noise and missing attributes to data sets. Also shows how to test a single learner on a range of data sets.
2# Category:    preprocessing
3# Uses:        imports-85
4# Referenced:  domain.htm
5
6import orange
7
8def report_prob(header, data):
9  print 'Size of %s: %i instances; ' % (header, len(data)), 
10  n = 0
11  for i in data:
12    if int(i.getclass())==0:
13      n = n + 1
14  if len(data):
15    print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data))
16  else:
17    print
18
19filename = "../datasets/adult_sample.tab"
20data = orange.ExampleTable(filename)
21report_prob('data', data)
22
23selection = [1]*10 + [0]*(len(data)-10)
24data1 = data.select(selection)
25report_prob('data1, first ten instances', data1)
26
27data2 = data.select(selection, negate=1)
28report_prob('data2, other than first ten instances', data2)
29
30selection = [1]*12 + [2]*12 + [3]*12 + [0]*(len(data)-12*3)
31data3 = data.select(selection, 3)
32report_prob('data3, third dozen of instances', data3)
Note: See TracBrowser for help on using the repository browser.