source: orange/docs/reference/rst/code/scoring-diff-measures.py @ 9823:7f9c3f3c6474

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