source: orange/orange/doc/ofb/domain9.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 1.6 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line 
1# Description: A simple implementation of wrapper feature subset selection
2# Category:    modelling
3# Uses:        imports-85
4# Classes:     Domain, orngTest.crossValidation
5# Referenced:  domain.htm
6
7import orange, orngTest, orngStat, orngTree
8
9def WrapperFSS(data, learner, verbose=0, folds=10):
10  classVar = data.domain.classVar
11  currentAtt = []
12  freeAttributes = list(data.domain.attributes)
13
14  newDomain = orange.Domain(currentAtt + [classVar])
15  d = data.select(newDomain)
16  results = orngTest.crossValidation([learner], d, folds=folds)
17  maxStat = orngStat.CA(results)[0]
18  if verbose>=2:
19    print "start (%5.3f)" % maxStat
20
21  while 1:
22    stat = []
23    for a in freeAttributes:
24      newDomain = orange.Domain([a] + currentAtt + [classVar])
25      d = data.select(newDomain)
26      results = orngTest.crossValidation([learner], d, folds=folds)
27      stat.append(orngStat.CA(results)[0])
28      if verbose>=2:
29        print %s gained %5.3f" % (a.name, orngStat.CA(results)[0])
30
31    if (max(stat) > maxStat):
32      oldMaxStat = maxStat
33      maxStat = max(stat)
34      bestVarIndx = stat.index(max(stat))
35      if verbose:
36        print "gain: %5.3f, attribute: %s" % (maxStat-oldMaxStat, freeAttributes[bestVarIndx].name)
37      currentAtt = currentAtt + [freeAttributes[bestVarIndx]]
38      del freeAttributes[bestVarIndx]
39    else:
40      if verbose:
41        print "stopped (%5.3f)" % (max(stat) - maxStat)
42      return orange.Domain(currentAtt + [classVar])
43      break
44
45data = orange.ExampleTable("voting")
46learner = orngTree.TreeLearner(mForPruning=0.5)
47#learner = orange.BayesLearner()
48
49bestDomain = WrapperFSS(data, learner, verbose=1)
50print bestDomain
Note: See TracBrowser for help on using the repository browser.