Пример #1
0
    def build_tree(self, X, y):
        """

        Args:
            X: object-features matrix
            y: target vector

        Returns:
            A `BinaryDecisionTree` fitted to the dataset.

            The actual structure of the tree depends both on dataset and the parameters
            passed to the `TreeBuilderCART` constructor.

        """
        n_samples, n_features = X.shape
        tree = BinaryDecisionTree(n_features=n_features)
        if self.n_jobs > 1:
            self.pool = Pool(self.n_jobs)

        leaf_to_split = tree.root()
        self._build_tree_recursive(tree, leaf_to_split, X, y)
        self._prune_tree(tree, X, y)
        if TreeBuilderCART.debug:
            TreeBuilderCART.logger.debug(tree)
        self.pool = None
        return tree