source: orange/docs/reference/rst/code/ @ 9823:7f9c3f3c6474

Revision 9823:7f9c3f3c6474, 1.4 KB checked in by lanumek, 2 years ago (diff)

Changed names of data sets (table replaced with data or name of the data set).

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
10import Orange, orngTest, orngStat
11voting ="voting")
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, voting, storeClassifiers=1)
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])
24# find out which attributes were retained by filtering
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 in attsUsed.keys():
31            attsUsed[] += 1
32        else:
33            attsUsed[] = 1
34for k in attsUsed.keys():
35    print "%2d x %s" % (attsUsed[k], k)
Note: See TracBrowser for help on using the repository browser.