python - 如何在 python 的 lightgbm 中计算 split_gain
问题描述
我想知道 lightgbm 如何计算 split_gain。我split_gain = sum_grad / sum_hess
在这里看到的。
但是,我看到那不是真的。来源如下。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from lightgbm import LGBMRegressor
from lightgbm.plotting import *
d = pd.DataFrame({"x1":[-2, -1, 0, 1, 2],"y":[4, 1, 0, 1, 4]})
def custom_asymmetric_train(y_true, y_pred):
residual = (y_true - y_pred).astype("float")
grad = np.where(residual<0, -2*10.0*residual, -2*residual)
hess = np.where(residual<0, 2*10.0, 2)
print(grad, hess, sum(grad), sum(hess))
return grad, hess
l2 = LGBMRegressor(min_child_samples=1, min_child_weight=0, n_estimators=5, max_depth=1, learning_rate=1, min_gain_to_split=0, objective=custom_asymmetric_train)
l2.fit(d[["x1"]], d[["y"]].values.ravel())
create_tree_digraph(booster=l2, show_info=['split_gain', 'internal_value', 'internal_count', 'leaf_count'], tree_index=0)
输出是
[-8. -2. -0. -2. -8.] [2. 2. 2. 2. 2.] -20.0 10.0
[-4.66666667 13.33333333 33.33333333 30. -3. ] [ 2. 20. 20. 20. 2.] 68.99999999999999 64.0
[-5.45454544 5.4545456 4.60317521 1.26984188 -5.87301581] [ 2. 20. 20. 20. 2.] 1.4305114603985203e-06 64.0
[-5.67374426 3.26255743 2.41118704 5.45454549 -5.45454545] [ 2. 20. 20. 20. 2.] 2.3841856311435095e-07 64.0
[-5.45454547 5.45454533 1.26300278 4.30636123 -5.56936388] [ 2. 20. 20. 20. 2.] -1.509903313490213e-14 64.0
我尝试了另一种情况,但我不知道 lgbm 是如何计算分割增益的。
请告诉我。
解决方案
推荐阅读
- vue.js - 在 NativeScript + Vue 中读取 ID3 标签
- junit - Mockito 在 Spring Boot 服务类中不起作用
- java - 应用程序未在 Android Pie 9 的发布版本中获取 mysql db
- javascript - Jquery-如何设置今天之前的日期无法选择?
- operating-system - 如何拥有多个鼠标光标或模拟多个鼠标但不在同一台计算机上移动我的光标?
- javascript - 文件上传功能正在本地主机上运行,但我无法在在线服务器上上传文件
- c# - 如何在 C# .Net WEB API 中以 JSON 形式返回 SQL 表
- mysql - 选择两列不等于 0 的计数
- macos - vulkan 管道布局兼容性
- asp.net - 如何避免视图中的重复值