source: orange/Orange/testing/regression/tests_20/reference_pp-weights.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 1.6 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 reweight the examples to modify the class distribution
2# Category:    preprocessing, weighting
3# Classes:     Preprocessor, Preprocessor_addClassWeight
4# Uses:        lenses
5# Referenced:  preprocessing.htm
6
7import orange
8data = orange.ExampleTable("lenses")
9age, prescr, astigm, tears, y = data.domain.variables
10
11pp = orange.Preprocessor_addClassWeight()
12pp.classWeights = [2.0, 1.0, 1.0]
13data2, weightID = pp(data)
14# we add a meta attribute so that output is always the same
15# (else, the meta id would depend upon the number of meta attributes
16# constructed, which would trigger suspicions about randomness in testing scripts
17data2.domain.addmeta(weightID, orange.FloatVariable("W"))
18
19print "Assigning weight 2.0 to examples from the first class"
20print "  - original class distribution: ", orange.Distribution(y, data2)
21print "  - weighted class distribution: ", orange.Distribution(y, data2, weightID)
22
23pp.classWeights = None
24pp.equalize = 1
25data2, weightID = pp(data)
26data2.domain.addmeta(weightID, orange.FloatVariable("W"))
27
28print "\nEqualizing class distribution"
29print "  - original class distribution: ", orange.Distribution(y, data2)
30print "  - weighted class distribution: ", orange.Distribution(y, data2, weightID)
31
32
33pp.classWeights = [0.5, 0.25, 0.25]
34pp.equalize = 1
35data2, weightID = pp(data)
36data2.domain.addmeta(weightID, orange.FloatVariable("W"))
37
38print "\nEqualizing class distribution and weighting by [0.5, 0.25, 0.25]"
39print "  - original class distribution: ", orange.Distribution(y, data2)
40print "  - weighted class distribution: ", orange.Distribution(y, data2, weightID)
Note: See TracBrowser for help on using the repository browser.