【发布时间】:2021-06-03 02:23:55
【问题描述】:
我们可以使用tree_to_dataframe或lgb.create_tree_digraph来展示lightgbm模型的结构。内部节点和叶子节点都有weight和value。
文件说:
value:float64,这个叶节点的预测值,乘以学习率。
weight:float64 或 int64,hessian 的总和(目标的二阶导数),对落在该节点的观察求和。 这两个值是怎么计算出来的?
- $H$ 不会是 $0$,因为在创建第一棵树之前我们有一个
base value,但是为什么在下面的示例中每个树的根节点中的权重是 $0$? - 内部节点的
value是如何计算的?
import lightgbm as lgb
import numpy as np
import pandas as pd
import sklearn
X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)
model = lgb.LGBMClassifier(random_state=1, n_estimators=2,
max_depth=1,
min_child_weight=15,
objective='binary'
)
model.fit(X, y)
model.booster_.trees_to_dataframe()
| tree_index | node_depth | node_index | left_child | right_child | parent_index | split_feature | split_gain | threshold | decision_type | missing_direction | missing_type | value | weight | count | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0-S0 | 0-L0 | 0-L1 | Column_23 | 392.505 | 868.2 | <= | left | None | 0.52115 | 0 | 569 | |
| 1 | 0 | 2 | 0-L0 | 0-S0 | nan | nan | 0.641339 | 89.2982 | 382 | ||||||
| 2 | 0 | 2 | 0-L1 | 0-S0 | nan | nan | 0.275629 | 43.7141 | 187 | ||||||
| 3 | 1 | 1 | 1-S0 | 1-L0 | 1-L1 | Column_7 | 327.362 | 0.05142 | <= | left | None | 0 | 0 | 569 | |
| 4 | 1 | 2 | 1-L0 | 1-S0 | nan | nan | 0.128938 | 79.2656 | 349 | ||||||
| 5 | 1 | 2 | 1-L1 | 1-S0 | nan | nan | -0.19224 | 52.9234 | 220 |
lgb.create_tree_digraph(model, tree_index=0, show_info=['split_gain', 'internal_value', 'internal_count',
'internal_weight', 'leaf_count', 'leaf_weight', 'data_percentage'])
lgb.create_tree_digraph(model, tree_index=0, show_info=['split_gain', 'internal_value', 'internal_count',
'internal_weight', 'leaf_count', 'leaf_weight', 'data_percentage'])
【问题讨论】:
标签: python machine-learning decision-tree lightgbm