How to use the kaggler.util.count_dict function in Kaggler

To help you get started, we’ve selected a few Kaggler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jeongyoonlee / Kaggler / kaggler / online_model / classification_tree.py View on Github external
def _apply_best_split(self):
        best_split, best_split_score = self._find_best_split()
        if best_split_score > 0:
            self.criterion = lambda x: x[best_split['feature']] \
                             > best_split['value']
            # create the left child
            self.left = ClassificationTree(
                number_of_features=self.number_of_features,
                number_of_functions=self.number_of_functions,
                min_sample_split=self.min_sample_split,
                predict_initialize={
                    'count_dict': count_dict(best_split['left']),
                }
            )
            # create the right child
            self.right = ClassificationTree(
                number_of_features=self.number_of_features,
                number_of_functions=self.number_of_functions,
                min_sample_split=self.min_sample_split,
                predict_initialize={
                    'count_dict': count_dict(best_split['right']),
                }
            )
            # Collect garbage
            self.samples = {}
            self.Y = []
github jeongyoonlee / Kaggler / kaggler / online_model / classification_tree.py View on Github external
def predict(self, x):
        """
        Make prediction recursively. Use both the samples inside the current
        node and the statistics inherited from parent.
        """
        if self._is_leaf():
            d1 = self.predict_initialize['count_dict']
            d2 = count_dict(self.Y)
            for key, value in d1.items():
                if key in d2:
                    d2[key] += value
                else:
                    d2[key] = value
            return argmax(d2)
        else:
            if self.criterion(x):
                return self.right.predict(x)
            else:
                return self.left.predict(x)