source: orange/orange/doc/modules/fss3.py @ 6538:a5f65d7f0b2c

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

Made XPM version of the icon 32x32.

Line 
1# Description: Compares naive Bayes with and withouth feature subset selection
2# Category:    preprocessing
3# Uses:        voting.tab
4# Referenced:  orngFSS.htm
5# Classes:     orngFSS.attMeasure, orngFSS.selectBestNAtts
6
7import orange, orngFSS
8
9class BayesFSS(object):
10  def __new__(cls, examples=None, **kwds):
11    learner = object.__new__(cls, **kwds)
12    if examples:
13      return learner(examples)
14    else:
15      return learner
16   
17  def __init__(self, name='Naive Bayes with FSS', N=5):
18    self.name = name
19    self.N = 5
20     
21  def __call__(self, data, weight=None):
22    ma = orngFSS.attMeasure(data)
23    filtered = orngFSS.selectBestNAtts(data, ma, self.N)
24    model = orange.BayesLearner(filtered)
25    return BayesFSS_Classifier(classifier=model, N=self.N, name=self.name)
26
27class BayesFSS_Classifier:
28  def __init__(self, **kwds):
29    self.__dict__.update(kwds)
30   
31  def __call__(self, example, resultType = orange.GetValue):
32    return self.classifier(example, resultType)
33
34# test above wraper on a data set
35import orngStat, orngTest
36data = orange.ExampleTable("voting")
37learners = (orange.BayesLearner(name='Naive Bayes'), BayesFSS(name="with FSS"))
38results = orngTest.crossValidation(learners, data)
39
40# output the results
41print "Learner      CA"
42for i in range(len(learners)):
43  print "%-12s %5.3f" % (learners[i].name, orngStat.CA(results)[i])
Note: See TracBrowser for help on using the repository browser.