source: orange/docs/reference/rst/code/randomindices2.py @ 9696:26fc745b27f6

Revision 9696:26fc745b27f6, 1.7 KB checked in by Jure Zbontar <jure.zbontar@…>, 2 years ago (diff)

Renamed RandomGenerator to Random in docs.

Line 
1# Description: Shows how to sample example by random divisions into two groups
2# Category:    sampling
3# Classes:     SubsetIndices2, RandomGenerator
4# Uses:        lenses
5# Referenced:  RandomIndices.htm
6
7import Orange
8
9data = Orange.data.Table("lenses")
10
11indices2 = Orange.data.sample.SubsetIndices2(p0=6)
12
13ind = indices2(data)
14print ind
15data0 = data.select(ind, 0)
16data1 = data.select(ind, 1)
17print len(data0), len(data1)
18
19print "\nIndices without playing with random generator"
20for i in range(5):
21    print indices2(data)
22
23print "\nIndices with random generator"
24indices2.random_generator = Orange.misc.Random(42)   
25for i in range(5):
26    print indices2(data)
27
28print "\nIndices with randseed"
29indices2.random_generator = None
30indices2.randseed = 42
31for i in range(5):
32    print indices2(data)
33
34
35print "\nIndices with p0 set as probability (not 'a number of')"
36indices2.p0 = 0.25
37print indices2(data)
38
39print "\n... with stratification"
40indices2.stratified = indices2.Stratified
41ind = indices2(data)
42print ind
43data2 = data.select(ind)
44od = Orange.core.getClassDistribution(data)
45sd = Orange.core.getClassDistribution(data2)
46od.normalize()
47sd.normalize()
48print od
49print sd
50
51print "\n... and without stratification"
52indices2.stratified = indices2.NotStratified
53print indices2(data)
54ind = indices2(data)
55print ind
56data2 = data.select(ind)
57od = Orange.core.getClassDistribution(data)
58sd = Orange.core.getClassDistribution(data2)
59od.normalize()
60sd.normalize()
61print od
62print sd
63
64print "\n... stratified 'if possible'"
65indices2.stratified = indices2.StratifiedIfPossible
66print indices2(data)
67
68print "\n... stratified 'if possible', after removing the first example's class"
69data[0].setclass("?")
70print indices2(data)
Note: See TracBrowser for help on using the repository browser.