I wonder how lightgbm compute split_gain.
I saw split_gain = sum_grad / sum_hess at here.
but, I saw that is not true. Source is below.
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)
and output is
[-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
I have tried another conditions, but I didn't know how lgbm comput split gain.
let me know please.
