Exemplo n.º 1
0
    def __init__(self,
                 booster: Booster,
                 tree_index: int,
                 x_data,
                 y_data,
                 feature_names: List[str] = None,
                 target_name: str = None,
                 class_names: (List[str], Mapping[int, str]) = None):
        if hasattr(booster, 'get_booster'):
            booster = booster.get_booster(
            )  # support XGBClassifier and XGBRegressor
        utils.check_tree_index(tree_index, len(booster.get_dump()))
        self.booster = booster
        self.tree_index = tree_index
        self.tree_to_dataframe = self._get_tree_dataframe()
        self.children_left = self._calculate_children(
            self.__class__.LEFT_CHILDREN_COLUMN)
        self.children_right = self._calculate_children(
            self.__class__.RIGHT_CHILDREN_COLUMN)
        self.config = json.loads(self.booster.save_config())
        self.node_to_samples = None  # lazy initialized
        self.features = None  # lazy initialized

        super().__init__(booster, x_data, y_data, feature_names, target_name,
                         class_names)
Exemplo n.º 2
0
    def __init__(self,
                 booster: Booster,
                 tree_index: int,
                 x_data: (pd.DataFrame, np.ndarray),
                 y_data: (pd.Series, np.ndarray),
                 feature_names: List[str] = None,
                 target_name: str = None,
                 class_names: (List[str], Mapping[int, str]) = None):

        utils.check_tree_index(tree_index, booster.num_trees())
        self.booster = booster
        self.tree_index = tree_index
        self.tree_nodes, self.children_left, self.children_right = self._get_nodes_info()
        self.thresholds = None  # lazy evaluation
        self.features = None  # lazy evaluation
        self.node_to_samples = None

        super().__init__(booster, x_data, y_data, feature_names, target_name, class_names)