source: orange/docs/reference/rst/code/selection-filtered-learner.py @ 9372:aef193695ea9

Revision 9372:aef193695ea9, 1.4 KB checked in by mitar, 2 years ago (diff)

Moved documentation to the separate directory.

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