source: orange/Orange/testing/regression/tests_20/reference_randomindices2.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 1.7 KB checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line 
1# Description: Shows how to sample example by random divisions into two groups
2# Category:    sampling
3# Classes:     MakeRandomIndices, MakeRandomIndices2, RandomGenerator
4# Uses:        lenses
5# Referenced:  RandomIndices.htm
6
7import orange
8
9data = orange.ExampleTable("lenses")
10
11indices2 = orange.MakeRandomIndices2(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.randomGenerator = orange.RandomGenerator(42)   
25for i in range(5):
26    print indices2(data)
27
28print "\nIndices with randseed"
29indices2.randomGenerator = 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.getClassDistribution(data)
45sd = orange.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.getClassDistribution(data)
58sd = orange.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.