source: orange/Orange/doc/ofb/nbdisc.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 1.0 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

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.