# source:orange/Orange/doc/modules/fss4.py@9671:a7b056375472

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

Moved orange to Orange (part 2)

Line
1# Description: Demonstrates the use of orngFSS.FilteredLearner to compare
2#              naive Bayesian learner when all or just the most important attribute
3#              is used. Shows how to find out which (in ten-fold cross validation)
4#              attributes was used the most.
5# Category:    preprocessing
6# Uses:        voting.tab
7# Referenced:  orngFSS.htm
8# Classes:     orngFSS.FilteredLearner
9
10import orange, orngFSS, orngTest, orngStat
11data = orange.ExampleTable("voting")
12
13nb = orange.BayesLearner()
14learners = (orange.BayesLearner(name='bayes'),
15            orngFSS.FilteredLearner(nb, filter=orngFSS.FilterBestNAtts(n=1), name='filtered'))
16results = orngTest.crossValidation(learners, data, storeClassifiers=1)
17
18# output the results
19print "Learner      CA"
20for i in range(len(learners)):
21  print "%-12s %5.3f" % (learners[i].name, orngStat.CA(results)[i])
22
23# find out which attributes were retained by filtering
24
25print "\nNumber of times attributes were used in cross-validation:"
26attsUsed = {}
27for i in range(10):
28  for a in results.classifiers[i][1].atts():
29    if a.name in attsUsed.keys(): attsUsed[a.name] += 1
30    else: attsUsed[a.name] = 1
31for k in attsUsed.keys():
32  print "%2d x %s" % (attsUsed[k], k)
Note: See TracBrowser for help on using the repository browser.