INNER CODE UNIT · Python

build_tree

ankonzoid/LearningX · basic_ML/classification/decision_tree.py:74

        def build_tree(X, y):
            X_left, y_left, X_right, y_right, split, threshold, j_threshold = perform_split(X, y)
            if split:
                child_left = build_tree(X_left, y_left)
                child_right = build_tree(X_right, y_right)
                node = {"split": split,
                        "threshold": threshold,
                        "j_threshold": j_threshold,
                        "child_left": child_left,
                        "child_right": child_right}
            else:
                node = {"value": max(set(list(y)), key=list(y).count)}
            return node

        self.tree = build_tree(X, y)

    def predict(self, X):

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…