source: orange/docs/tutorial/rst/code/nbdisc.py @ 9374:59bac7ddd8a2

Revision 9374:59bac7ddd8a2, 1.0 KB checked in by mitar, 2 years ago (diff)

Tutorial documentation structure.

Line 
1# Description: Class that embeds naive Bayesian classifier, but when learning discretizes the data with entropy-based discretization (which uses training data only)
2# Category:    modelling
3# Referenced:  c_nb_disc.htm
4
5import orange
6
7class Learner(object):
8    def __new__(cls, examples=None, name='discretized bayes', **kwds):
9        learner = object.__new__(cls, **kwds)
10        if examples:
11            learner.__init__(name) # force init
12            return learner(examples)
13        else:
14            return learner  # invokes the __init__
15
16    def __init__(self, name='discretized bayes'):
17        self.name = name
18
19    def __call__(self, data, weight=None):
20        disc = orange.Preprocessor_discretize( \
21            data, method=orange.EntropyDiscretization())
22        model = orange.BayesLearner(disc, weight)
23        return Classifier(classifier = model)
24
25class Classifier:
26    def __init__(self, **kwds):
27        self.__dict__.update(kwds)
28
29    def __call__(self, example, resultType = orange.GetValue):
30        return self.classifier(example, resultType)
Note: See TracBrowser for help on using the repository browser.