source: orange/Orange/doc/reference/CostMatrix.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 1.6 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1# Description: Shows how to assess the quality of attributes not in the dataset
2# Category:    attribute quality
3# Classes:     EntropyDiscretization, MeasureAttribute, MeasureAttribute_info
4# Uses:        iris
5# Referenced:  MeasureAttribute.htm
6
7import orange
8
9print
10print "Default matrix of size 3"
11cm = orange.CostMatrix(3)
12print "classVar =", cm.classVar
13for pred in range(3):
14    for corr in range(3):
15        print cm.getcost(pred, corr),
16    print
17
18print
19print "Matrix for Iris, with default element 2 and several modified elements"
20data = orange.ExampleTable("iris")
21cm = orange.CostMatrix(data.domain.classVar, 2)
22cm.setcost("Iris-setosa", "Iris-virginica", 1)
23cm.setcost("Iris-versicolor", "Iris-virginica", 1)
24
25print "classVar = %s, values = %s" % (cm.classVar.name, cm.classVar.values)
26for pred in range(3):
27    for corr in range(3):
28        print cm.getcost(pred, corr),
29    print
30
31print
32print "Manually initialized matrix"
33cm = orange.CostMatrix(data.domain.classVar, [(0, 2, 1), (2, 0, 1), (2, 2, 0)])
34for pred in range(3):
35    for corr in range(3):
36        print `cm.getcost(pred, corr)`,
37    print
38
39data = orange.ExampleTable("lenses")
40print
41print "Cost-sensitive attribute quality"
42meas = orange.MeasureAttribute_cost()
43meas.cost = ((0, 2, 1), (2, 0, 1), (2, 2, 0))
44for attr in data.domain.attributes:
45    print "%s: %5.3f" % (attr.name, meas(attr, data))
46print
47
48data = orange.ExampleTable("lenses")
49print
50print "Cost-sensitive attribute quality"
51meas = orange.MeasureAttribute_cost()
52meas.cost = data.domain.classVar
53for attr in data.domain.attributes:
54    print "%s: %5.3f" % (attr.name, meas(attr, data))
55print
Note: See TracBrowser for help on using the repository browser.