source: orange/docs/reference/rst/code/randomindices2.py @ 9823:7f9c3f3c6474

Revision 9823:7f9c3f3c6474, 1.7 KB checked in by lanumek, 2 years ago (diff)

Changed names of data sets (table replaced with data or name of the data set).

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
9lenses = Orange.data.Table("lenses")
10
11indices2 = Orange.data.sample.SubsetIndices2(p0=6)
12
13ind = indices2(lenses)
14print ind
15lenses0 = lenses.select(ind, 0)
16lenses1 = lenses.select(ind, 1)
17print len(lenses0), len(lenses1)
18
19print "\nIndices without playing with random generator"
20for i in range(5):
21    print indices2(lenses)
22
23print "\nIndices with random generator"
24indices2.random_generator = Orange.core.RandomGenerator(42)   
25for i in range(5):
26    print indices2(lenses)
27
28print "\nIndices with randseed"
29indices2.random_generator = None
30indices2.randseed = 42
31for i in range(5):
32    print indices2(lenses)
33
34
35print "\nIndices with p0 set as probability (not 'a number of')"
36indices2.p0 = 0.25
37print indices2(lenses)
38
39print "\n... with stratification"
40indices2.stratified = indices2.Stratified
41ind = indices2(lenses)
42print ind
43lenses2 = lenses.select(ind)
44od = Orange.core.getClassDistribution(lenses)
45sd = Orange.core.getClassDistribution(lenses2)
46od.normalize()
47sd.normalize()
48print od
49print sd
50
51print "\n... and without stratification"
52indices2.stratified = indices2.NotStratified
53print indices2(lenses)
54ind = indices2(lenses)
55print ind
56lenses2 = lenses.select(ind)
57od = Orange.core.getClassDistribution(lenses)
58sd = Orange.core.getClassDistribution(lenses2)
59od.normalize()
60sd.normalize()
61print od
62print sd
63
64print "\n... stratified 'if possible'"
65indices2.stratified = indices2.StratifiedIfPossible
66print indices2(lenses)
67
68print "\n... stratified 'if possible', after removing the first example's class"
69lenses[0].setclass("?")
70print indices2(lenses)
Note: See TracBrowser for help on using the repository browser.