tabular_trees.ScikitLearnTabularTrees

class tabular_trees.ScikitLearnTabularTrees(data)[source]

Bases: BaseModelTabularTrees

Scikit-Learn GradientBoosting trees in tabular format.

The preferred way to create ScikitLearnTabularTrees objects is with the from_gradient_booster method.

__init__(data)

Methods

__init__(data)

from_gradient_booster(model)

Export from a GradientBoostingClassifier or GradientBoostingRegressor.

to_dataframe()

Return data for trees object.

Attributes

data

Tree data.

tree

Tree index.

node

Node index.

children_left

Left child node index.

children_right

Right child node index.

feature

Split feature index.

impurity

Impurity at node.

n_node_samples

Number of records at node.

threshold

Split threshold.

value

Split value.

weighted_n_node_samples

Weight at node.

children_left

Left child node index.

children_right

Right child node index.

data

Tree data.

feature

Split feature index.

classmethod from_gradient_booster(model)[source]

Export from a GradientBoostingClassifier or GradientBoostingRegressor.

Parameters:

model (Union[GradientBoostingClassifier, GradientBoostingRegressor]) – GradientBoostingRegressor or Classifier tree data extracted from the .estimators_ attribute.

Returns:

trees – Model trees in tabular format.

Return type:

ScikitLearnTabularTrees

Examples

>>> from sklearn.datasets import load_diabetes
>>> from sklearn.ensemble import GradientBoostingRegressor
>>> from tabular_trees import ScikitLearnTabularTrees
>>> # load data
>>> diabetes = load_diabetes()
>>> # build model
>>> model = GradientBoostingRegressor(max_depth=3, n_estimators=10)
>>> model.fit(diabetes["data"], diabetes["target"])
GradientBoostingRegressor(n_estimators=10)
>>> # export to ScikitLearnTabularTrees
>>> sklearn_tabular_trees = ScikitLearnTabularTrees.from_gradient_booster(model)
>>> type(sklearn_tabular_trees)
<class 'tabular_trees.sklearn.sklearn_tabular_trees.ScikitLearnTabularTrees'>
impurity

Impurity at node.

n_node_samples

Number of records at node.

node

Node index.

threshold

Split threshold.

to_dataframe()

Return data for trees object.

Returns:

trees – Model trees in DataFrame form.

Return type:

pd.DataFrame

tree

Tree index.

value

Split value.

weighted_n_node_samples

Weight at node.