tabular_trees.ScikitLearnTabularTrees
- class tabular_trees.ScikitLearnTabularTrees(data)[source]
Bases:
BaseModelTabularTreesScikit-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.
Return data for trees object.
Attributes
Tree data.
Tree index.
Node index.
Left child node index.
Right child node index.
Split feature index.
Impurity at node.
Number of records at node.
Split threshold.
Split value.
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:
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.