Changeset 9661:674777da09b9 in orange


Ignore:
Timestamp:
02/06/12 09:11:20 (2 years ago)
Author:
Miha Stajdohar <miha.stajdohar@…>
Branch:
default
Message:

To Orange25.

Location:
docs/reference/rst/code
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • docs/reference/rst/code/selection-bayes.py

    r9372 r9661  
    33# Uses:        voting 
    44# Referenced:  Orange.feature.html#selection 
    5 # Classes:     Orange.feature.scoring.score_all, Orange.feature.selection.bestNAtts 
     5# Classes:     Orange.feature.scoring.score_all, Orange.feature.selection.best_n 
    66 
    77import Orange 
     
    1515        else: 
    1616            return learner 
    17      
     17 
    1818    def __init__(self, name='Naive Bayes with FSS', N=5): 
    1919        self.name = name 
    2020        self.N = 5 
    21        
    22     def __call__(self, table, weight=None): 
    23         ma = Orange.feature.scoring.score_all(table) 
    24         filtered = Orange.feature.selection.selectBestNAtts(table, ma, self.N) 
     21 
     22    def __call__(self, data, weight=None): 
     23        ma = Orange.feature.scoring.score_all(data) 
     24        filtered = Orange.feature.selection.select_best_n(data, ma, self.N) 
    2525        model = Orange.classification.bayes.NaiveLearner(filtered) 
    2626        return BayesFSS_Classifier(classifier=model, N=self.N, name=self.name) 
     
    2929    def __init__(self, **kwds): 
    3030        self.__dict__.update(kwds) 
    31      
    32     def __call__(self, example, resultType = Orange.core.GetValue): 
     31 
     32    def __call__(self, example, resultType=Orange.core.GetValue): 
    3333        return self.classifier(example, resultType) 
    3434 
    3535 
    3636# test above wraper on a data set 
    37 table = Orange.data.Table("voting") 
     37voting = Orange.data.Table("voting") 
    3838learners = (Orange.classification.bayes.NaiveLearner(name='Naive Bayes'), 
    3939            BayesFSS(name="with FSS")) 
    40 results = Orange.evaluation.testing.cross_validation(learners, table) 
     40results = Orange.evaluation.testing.cross_validation(learners, voting) 
    4141 
    4242# output the results 
  • docs/reference/rst/code/selection-filtered-learner.py

    r9372 r9661  
    88# Classes:     Orange.feature.selection.FilteredLearner 
    99 
    10 import Orange, orngTest, orngStat 
    11 table = Orange.data.Table("voting") 
     10import Orange 
     11 
     12voting = Orange.data.Table("voting") 
    1213 
    1314nb = Orange.classification.bayes.NaiveLearner() 
    14 fl = Orange.feature.selection.FilteredLearner(nb,  
    15      filter=Orange.feature.selection.FilterBestNAtts(n=1), name='filtered') 
     15fl = Orange.feature.selection.FilteredLearner(nb, 
     16     filter=Orange.feature.selection.FilterBestN(n=1), name='filtered') 
    1617learners = (Orange.classification.bayes.NaiveLearner(name='bayes'), fl) 
    17 results = orngTest.crossValidation(learners, table, storeClassifiers=1) 
     18results = Orange.evaluation.testing.cross_validation(learners, voting, storeClassifiers=1) 
    1819 
    1920# output the results 
    2021print "Learner      CA" 
    2122for i in range(len(learners)): 
    22     print "%-12s %5.3f" % (learners[i].name, orngStat.CA(results)[i]) 
     23    print "%-12s %5.3f" % (learners[i].name, Orange.evaluation.scoring.CA(results)[i]) 
    2324 
    2425# find out which attributes were retained by filtering 
Note: See TracChangeset for help on using the changeset viewer.