source: orange/orange/doc/reference/pp-noise.py @ 526:fe2d65da2b2a

Revision 526:fe2d65da2b2a, 1.5 KB checked in by janezd <janez.demsar@…>, 10 years ago (diff)
  • moved documentation from a separate module to this one
Line 
1# Description: Shows how to add attribute and class noise
2# Category:    preprocessing, noise
3# Classes:     Preprocessor, Preprocessor_addClassNoise, Preprocessor_addGaussianClassNoise, Preprocessor_addNoise, Preprocessor_addClassNoise
4# Uses:        lenses
5# Referenced:  preprocessing.htm
6
7import orange
8data = orange.ExampleTable("lenses")
9age, prescr, astigm, tears, y = data.domain.variables
10
11print "50% class noise (on lenses)\n"
12data2 = orange.Preprocessor_addClassNoise(data, proportion = 0.5)
13for i in range(len(data)):
14    print data[i].getclass(), data2[i].getclass()
15
16print "\n\nGaussian noise with deviation 10\n"
17cdomain = orange.Domain([orange.FloatVariable()])
18cdata = orange.ExampleTable(cdomain, [[100]]*20)
19cdata2 = orange.Preprocessor_addGaussianClassNoise(cdata, deviation=10)
20for i in cdata2:
21    print i.getclass(),
22print
23
24
25print "\n\n30% noise in age, 50% in prescription and 20% elsewhere\n"
26pp = orange.Preprocessor_addNoise()
27pp.proportions[age]=0.3
28pp.proportions[prescr]=0.5
29pp.defaultProportion = 0.2
30data2 = pp(data)
31for i in range(len(data)):
32    print "%s\n%s\n" % (data[i], data2[i])
33
34print "\n\nGaussian noise with deviation 5.0 in all attributes except petal width\n"
35iris = orange.ExampleTable("iris")
36for attr in iris.domain.attributes:
37    attr.numberOfDecimals = 3
38   
39pp = orange.Preprocessor_addGaussianNoise()
40pp.deviations[iris.domain["petal width"]] = 0.0
41pp.defaultDeviation = 1.0
42data2 = pp(iris)
43for i in range(10):
44    print "%s\n%s\n" % (iris[i], data2[i])
Note: See TracBrowser for help on using the repository browser.