def learn_from_instance(self, X, y, weight, ht): """ Update the node with the provided instance. Parameters ---------- X: numpy.ndarray of length equal to the number of features. Instance attributes for updating the node. y: int Instance class. weight: float Instance weight. ht: HoeffdingTree Hoeffding Tree to update. """ # Update attribute_observers try: self._observed_class_distribution[y] += weight except KeyError: self._observed_class_distribution[y] = weight for i in range(len(X)): try: obs = self._attribute_observers[i] except KeyError: if i in ht.nominal_attributes: obs = NominalAttributeClassObserver() else: obs = NumericAttributeClassObserverGaussian() self._attribute_observers[i] = obs obs.observe_attribute_class(X[i], int(y), weight)
def learn_from_instance(self, X, y, weight, ht): """Update the node with the provided instance. Parameters ---------- X: numpy.ndarray of length equal to the number of features. Instance attributes for updating the node. y: int Instance class. weight: float Instance weight. ht: HoeffdingTreeClassifier Hoeffding Tree to update. """ try: self._observed_class_distribution[y] += weight except KeyError: self._observed_class_distribution[y] = weight self._observed_class_distribution = dict( sorted(self._observed_class_distribution.items())) if self.list_attributes.size == 0: self.list_attributes = self._sample_features(get_dimensions(X)[1]) for i in self.list_attributes: try: obs = self._attribute_observers[i] except KeyError: if ht.nominal_attributes is not None and i in ht.nominal_attributes: obs = NominalAttributeClassObserver() else: obs = NumericAttributeClassObserverGaussian() self._attribute_observers[i] = obs obs.observe_attribute_class(X[i], int(y), weight)
def _partial_fit(self, X, y, weight): try: self._observed_class_distribution[y] += weight except KeyError: self._observed_class_distribution[y] = weight for i in range(len(X)): try: obs = self._attribute_observers[i] except KeyError: if i in self._nominal_attributes: obs = NominalAttributeClassObserver() else: obs = NumericAttributeClassObserverGaussian() self._attribute_observers[i] = obs obs.observe_attribute_class(X[i], int(y), weight)
def learn_from_instance(self, X, y, weight, ht): if not (ht.leaf_prediction == NAIVE_BAYES_ADAPTIVE): y = ''.join(str(e) for e in y) y = int(y, 2) try: self._observed_class_distribution[y] += weight except KeyError: self._observed_class_distribution[y] = weight for i in range(len(X)): try: obs = self._attribute_observers[i] except KeyError: if ht.nominal_attributes is not None and i in ht.nominal_attributes: obs = NominalAttributeClassObserver() else: obs = NumericAttributeClassObserverGaussian() self._attribute_observers[i] = obs obs.observe_attribute_class(X[i], int(y), weight)