current_depth): self.prob = [np.count_nonzero(y == i) / len(y) for i in range(num_of_class)] if current_depth <= max_depth: self.is_leaf = False self.gain, self.split_feature_index, self.split_threshold = calc_best_split_feature(x, y) feature_values = x[:, self.split_feature_index] x_left = x[feature_values <= self.split_threshold] x_right = x[feature_values > self.split_threshold] y_left = y[feature_values <= self.split_threshold] y_right = y[feature_values > self.split_threshold] if len(y_left) == 0 or len(y_right) == 0: self.is_leaf = True else: self.left_node = Node(x_left, y_left, num_of_class, max_depth, current_depth + 1) self.right_node = Node(x_right, y_right, num_of_class, max_depth, current_depth + 1) else: self.is_leaf = True max_depthに達するまで 再帰を繰り返す ゲイン最大の分割条件 (特徴量および閾値) を求め、データ分割 子ノードを作成