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

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

Tests moved and renamed from orange 20.

Line 
1# Description: Tests various classes for attribute quality assessment
2# Category:    attribute quality
3# Classes:     MeasureAttribute, MeasureAttribute_info, MeasureAttribute_gainRatio, MeasureAttribute_gini, MeasureAttribute_relevance, MeasureAttribute_cost, MeasureAttribute_Relief
4# Uses:        measure
5# Referenced:  MeasureAttribute.htm
6
7import orange, random
8data = orange.ExampleTable("measure")
9
10data2 = orange.ExampleTable(data)
11nulls = [(0, 1, 24, 25), (24, 25), range(24, 34), (24, 25)]
12for attr in range(len(nulls)):
13    for e in nulls[attr]:
14        data2[e][attr]="?"
15
16names = [a.name for a in data.domain.attributes]
17attrs = len(names)
18print
19print ("%30s"+"%15s"*attrs) % (("",) + tuple(names))
20fstr = "%30s" + "%15.4f"*attrs
21
22def printVariants(meas):
23    print fstr % (("- no unknowns:",) + tuple([meas(i, data) for i in range(attrs)]))
24
25    meas.unknownsTreatment = meas.IgnoreUnknowns
26    print fstr % (("- ignore unknowns:",) + tuple([meas(i, data2) for i in range(attrs)]))
27
28    meas.unknownsTreatment = meas.ReduceByUnknowns
29    print fstr % (("- reduce unknowns:",) + tuple([meas(i, data2) for i in range(attrs)]))
30
31    meas.unknownsTreatment = meas.UnknownsToCommon
32    print fstr % (("- unknowns to common:",) + tuple([meas(i, data2) for i in range(attrs)]))
33
34    meas.unknownsTreatment = meas.UnknownsAsValue
35    print fstr % (("- unknowns as value:",) + tuple([meas(i, data2) for i in range(attrs)]))
36    print
37   
38print "Information gain"
39printVariants(orange.MeasureAttribute_info())
40
41print "Gain ratio"
42printVariants(orange.MeasureAttribute_gainRatio())
43
44print "Gini index"
45printVariants(orange.MeasureAttribute_gini())
46
47print "Relief"
48meas = orange.MeasureAttribute_relief()
49print fstr % (("- no unknowns:",) + tuple([meas(i, data) for i in range(attrs)]))
50print fstr % (("- with unknowns:",) + tuple([meas(i, data2) for i in range(attrs)]))
51print
52
53print "Cost matrix ((0, 5), (1, 0))"
54meas = orange.MeasureAttribute_cost()
55meas.cost = ((0, 5), (1, 0))
56printVariants(meas)
57
58print "Relevance"
59printVariants(orange.MeasureAttribute_relevance())
Note: See TracBrowser for help on using the repository browser.