LightGBM histogram and growth
Quick answer
LightGBM uses binned feature values to search for useful tree splits and typically expands the available leaf with the best improvement. This can spend tree capacity on a difficult region instead of growing every branch evenly. Control leaf count, depth and minimum data per leaf to avoid overly detailed trees. Static examples tested locally with Python 3.13.5, XGBoost 3.1.3, LightGBM 4.6.0 and CatBoost 1.2.8 where imported. ByteMind package execution is unverified.
Accumulate histogram statistics
g=[-2,-1,1,2]h=[1,2,2,1]print([(sum(g[:i]),sum(h[:i])) for i in range(1,len(g))])Observed local output:
[(-2, 1), (-3, 3), (-2, 5)]Each pair is the gradient and Hessian mass to the left of a candidate cut; the right mass is total minus left.
How it works
A histogram stores aggregate gradient and Hessian statistics by feature bin. For a feature with B bins, once the histogram is built, a scan of B candidate boundaries can reuse cumulative sums rather than inspecting every training row for every candidate. Building the histogram still requires processing rows; the entire training algorithm is not O(B). For four ordered bins with gradient sums [-2,-1,1,2], splitting after bin two places -3 on the left and +3 on the right. Hessian sums and regularization are also needed to calculate gain. Histogram subtraction obtains one child histogram from the parent and sibling. Coarser bins reduce threshold resolution. In leaf-wise growth, a best-first choice may make one branch deep while another remains shallow. num_leaves limits the maximum leaf count; max_depth limits depth when positive; min_child_samples discourages tiny leaves. They are distinct constraints. Categorical columns can use nonnegative integer codes or compatible pandas category columns, explicitly treated as categories; numerical treatment would impose an artificial ordering. Negative categorical codes are treated as missing by this release. Freeze a consistent mapping from training rather than independently assigning codes per split.
Inspect native leaf count
import pandas as pdfrom lightgbm import LGBMRegressorX=pd.DataFrame({"load":list(range(12))})y=[0]*6+[4]*6m=LGBMRegressor(n_estimators=1,num_leaves=2,max_depth=1,min_child_samples=1,min_data_in_bin=1,learning_rate=1,n_jobs=1,verbosity=-1,random_state=7).fit(X,y)print(m.booster_.dump_model()["tree_info"][0]["num_leaves"])print([round(float(v),3) for v in m.predict(pd.DataFrame({"load":[0,11]}))])Observed local output:
2[0.0, 4.0]The shallow tree can separate the two target levels in this simple fixture.
Common mistakes
Do not infer max_depth from num_leaves as an equality or claim histogram binning makes the complete training cost independent of row count. LightGBM and XGBoost parameter names and growth policies are not interchangeable. Avoid comparing a depth-limited model with an unlimited model as if they have identical capacity.
Practice and next steps
Use the first example to inspect all three split candidates. Explain what changes when adjacent bins are merged. In the native example lower num_leaves and compare the number of leaves reported by the model. Complete the knowledge check and staged exercise. Next: CatBoost categorical processing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
LightGBM histogram and growth — knowledge check
Apply lightgbm histogram and growth to new scenarios.
What is stored in a gradient histogram?
What does leaf-wise growth prioritize?
What caps the number of leaves?
What may fewer bins sacrifice?
What do negative categorical codes represent in LightGBM 4.6?