tabular_trees.LightGBMTabularTrees
- class tabular_trees.LightGBMTabularTrees(data)[source]
Bases:
BaseModelTabularTreesClass to hold the LightGBM trees in tabular format.
The preferred way to create LightGBMTabularTrees objects is with the from_booster method.
- __init__(data)
Methods
__init__(data)from_booster(booster)Create LightGBMTabularTrees from a lgb.Booster object.
Return data for trees object.
Convert the tree data to a TabularTrees object.
Attributes
Tree data.
Tree index.
Depth of each node.
Unique identifier for each node in the tree.
Node index for left children.
Node index for right children.
Node index for the current node's parent.
Name of the feature used to split on.
Gain for splits.
Split threshold.
Direction at split for rows with null value for the split feature.
What types of values are considered missing.
Node predicton.
Sum of Hessian for node.
Count of rows at node.
- count
Count of rows at node.
- data
Tree data.
- decision_type
- classmethod from_booster(booster)[source]
Create LightGBMTabularTrees from a lgb.Booster object.
- Parameters:
booster (lgb.Booster) – LightGBM model to pull tree data from.
- Returns:
trees – Model trees in tabular format.
- Return type:
Examples
>>> import lightgbm as lgb >>> from sklearn.datasets import load_diabetes >>> from tabular_trees import LightGBMTabularTrees >>> # get data in Dataset >>> diabetes = load_diabetes() >>> data = lgb.Dataset(diabetes["data"], label=diabetes["target"]) >>> # build model >>> params = {"max_depth": 3, "verbosity": -1} >>> model = lgb.train(params, train_set=data, num_boost_round=10) >>> # export to LightGBMTabularTrees >>> lightgbm_tabular_trees = LightGBMTabularTrees.from_booster(model) >>> type(lightgbm_tabular_trees) <class 'tabular_trees.lightgbm.lightgbm_tabular_trees.LightGBMTabularTrees'>
- left_child
Node index for left children.
- missing_direction
Direction at split for rows with null value for the split feature.
- missing_type
What types of values are considered missing.
- node_depth
Depth of each node.
- node_index
Unique identifier for each node in the tree.
- parent_index
Node index for the current node’s parent.
- right_child
Node index for right children.
- split_feature
Name of the feature used to split on.
Null for leaf nodes.
- split_gain
Gain for splits.
Null for leaf nodes.
- threshold
Split threshold.
Null for leaf nodes.
- to_dataframe()
Return data for trees object.
- Returns:
trees – Model trees in DataFrame form.
- Return type:
pd.DataFrame
- to_tabular_trees()[source]
Convert the tree data to a TabularTrees object.
- Returns:
trees – Model trees in TabularTrees form.
- Return type:
- tree_index
Tree index.
- value
Node predicton.
- weight
Sum of Hessian for node.