tabular_trees.LightGBMTabularTrees

class tabular_trees.LightGBMTabularTrees(data)[source]

Bases: BaseModelTabularTrees

Class 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.

to_dataframe()

Return data for trees object.

to_tabular_trees()

Convert the tree data to a TabularTrees object.

Attributes

data

Tree data.

tree_index

Tree index.

node_depth

Depth of each node.

node_index

Unique identifier for each node in the tree.

left_child

Node index for left children.

right_child

Node index for right children.

parent_index

Node index for the current node's parent.

split_feature

Name of the feature used to split on.

split_gain

Gain for splits.

threshold

Split threshold.

decision_type

missing_direction

Direction at split for rows with null value for the split feature.

missing_type

What types of values are considered missing.

value

Node predicton.

weight

Sum of Hessian for node.

count

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:

LightGBMTabularTrees

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:

TabularTrees

tree_index

Tree index.

value

Node predicton.

weight

Sum of Hessian for node.