def get_class_votes(self, X, ht):

            dist = {}
            prediction_option = ht.leaf_prediction

            if prediction_option == MAJORITY_CLASS:  #MC
                dist = self.get_observed_class_distribution()
            elif prediction_option == NAIVE_BAYES:  #NB
                dist = do_naive_bayes_prediction(
                    X, self._observed_class_distribution,
                    self._attribute_observers)

            # NBAdaptive
            if self._mc_correct_weight > self._nb_correct_weight:
                dist = self.get_observed_class_distribution()
            else:
                dist = do_naive_bayes_prediction(
                    X, self._observed_class_distribution,
                    self._attribute_observers)

            dist_sum = sum(dist.values())  # sum all values in dictionary

            if dist_sum * self.get_error_estimation(
            ) * self.get_error_estimation() > 0.0:
                normalize_values_in_dict(
                    dist_sum * self.get_error_estimation() *
                    self.get_error_estimation(), dist)

            return dist
Example #2
0
 def get_class_votes(self, X, ht):
     if self.get_weight_seen() >= ht.nb_threshold:
         return do_naive_bayes_prediction(
             X, self._observed_class_distribution,
             self._attribute_observers)
     else:
         return super().get_class_votes(X, ht)
 def learn_from_instance(self, X, y, weight, ht):
     if self._observed_class_distribution == {}:
         # All classes equal, default to class 0
         if 0 == y:
             self._mc_correct_weight += weight
     elif max(self._observed_class_distribution, key=self._observed_class_distribution.get) == y:
         self._mc_correct_weight += weight
     nb_prediction = do_naive_bayes_prediction(
         X, self._observed_class_distribution, self._attribute_observers)
     if max(nb_prediction, key=nb_prediction.get) == y:
         self._nb_correct_weight += weight
     super().learn_from_instance(X, y, weight, ht)
Example #4
0
 def get_class_votes(self, X, ht):
     if self._mc_correct_weight > self._nb_correct_weight:
         return self._observed_class_distribution
     return do_naive_bayes_prediction(X,
                                      self._observed_class_distribution,
                                      self._attribute_observers)