LightGBM › Formula
Machine Learning from ScratchAll chapters LightGBM › FormulaOne section · Sections in this chapter3 / 9 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
The mathematical foundation of LightGBM builds upon the standard gradient boosting framework, but with key modifications to the tree construction process. Let's start with the fundamental gradient boosting objective function and then see how LightGBM optimizes it.
Note: The Loss function should look very similar to the one in XGBoost, hence we will not repeat the details here. Please refer to the XGBoost section for more detail.
The standard gradient boosting objective function combines a loss function with regularization terms:
where is the loss function, is the -th tree we're adding, and is the regularization term for the tree.
In LightGBM, we use a second-order Taylor expansion to approximate this objective:
where:
- : first-order gradient (the slope of the loss function with respect to the prediction for instance )
- : second-order gradient or Hessian (the curvature of the loss function with respect to the prediction for instance )
This second-order approximation provides a more accurate representation of the loss function around the current prediction.

The key innovation in LightGBM lies in its unique approach to constructing decision trees, which is fundamentally different from the traditional level-wise method used in most gradient boosting frameworks.
Let's break down the LightGBM tree construction process step by step:
-
Leaf-wise Growth Strategy:
- In traditional level-wise tree growth (as in XGBoost by default), all leaves at the current depth are split simultaneously, resulting in a balanced tree.
- LightGBM, however, adopts a leaf-wise (best-first) growth strategy. At each step, it searches among all current leaves and selects the one whose split would result in the largest reduction in the loss function (i.e., the greatest "gain").
- This means that LightGBM can grow deeper, more complex branches where the model can most effectively reduce error, potentially leading to higher accuracy with fewer trees.
-
Calculating the Split Gain:
- When considering splitting a particular leaf , LightGBM evaluates all possible splits and calculates the "gain" for each.
- The gain measures how much the split would reduce the overall loss function. The formula for the gain when splitting a leaf into left () and right () children is:
where:
- : first-order gradient (the derivative of the loss with respect to the prediction for instance )
- : second-order gradient (the second derivative, or curvature, of the loss for instance )
- : set of all instances in the current leaf before the split
- : set of instances that would go to the left child leaf after the split
- : set of instances that would go to the right child leaf after the split
- : L2 regularization parameter (helps prevent overfitting by penalizing large leaf weights)
- : minimum gain threshold required to make a split (splits with gain less than are not performed)
Observe that in the gain formula, each term of the form represents a fraction: the numerator is the square of the sum of gradients for a group of instances (such as all instances in the left child), and the denominator is the sum of the Hessians (second-order gradients) for those instances plus the regularization parameter .
This fraction reflects the confidence in the leaf's prediction.a larger sum of gradients (numerator) indicates a greater potential adjustment, while a larger sum of Hessians (denominator) or stronger regularization reduces the magnitude of that adjustment. The difference between the fractions for the left and right children and the original leaf quantifies the net reduction in loss achieved by making the split.
- Step-by-step Gain Calculation:
- a. For each possible split, sum the gradients () and Hessians () for the left and right child nodes.
- b. Compute the gain for the split using the formula above.
- c. Compare the gain to the threshold . If the gain is greater than , the split is considered valid.
- d. Among all possible splits across all leaves, select the split with the highest gain and perform it.
- e. Repeat this process, always splitting the leaf with the largest potential gain, until a stopping criterion is met (such as maximum tree depth, minimum number of samples in a leaf, or minimum gain).
This leaf-wise, best-first approach allows LightGBM to focus its modeling capacity where it is most needed, often resulting in faster convergence and higher accuracy compared to level-wise methods. However, because it can create deeper, more complex trees, it may also be more prone to overfitting, especially on small datasets.so regularization and early stopping are important.
In summary, LightGBM's step-by-step tree construction process is:
- At each iteration, evaluate all possible splits for all current leaves.
- Calculate the gain for each split using the gradients and Hessians.
- Select and perform the split with the highest gain (if it exceeds ).
- Repeat until stopping criteria are met.
This process is at the heart of LightGBM's efficiency and predictive power.
The Gradient-based One-Side Sampling (GOSS) technique is a core innovation in LightGBM that significantly accelerates training without sacrificing accuracy, especially on large datasets. GOSS is based on the observation that data instances with larger gradients (i.e., those that are currently poorly predicted by the model) contribute more to the information gain when building trees. Therefore, GOSS prioritizes these "hard" instances during the split-finding process.
GOSS proceeds through four steps:
-
Gradient Calculation:
- For each data instance, compute the gradient of the loss function with respect to the current prediction. The magnitude of the gradient reflects how much the model's prediction for that instance needs to be updated.
-
Instance Selection:
- Large-gradient instances: Select and retain all instances whose gradients are among the top fraction (e.g., the top 20%) of all gradients. These are the most "informative" samples for the current boosting iteration.
- Small-gradient instances: From the remaining instances (those with smaller gradients), randomly sample a subset, typically a fraction (e.g., 20%) of the total data. This ensures that the model still sees a representative sample of "easy" instances, but at a much lower computational cost.
-
Reweighting for Unbiased Estimation:
- Because the small-gradient instances are under-sampled, GOSS compensates by up-weighting their gradients and Hessians during the split gain calculation. Specifically, the gradients and Hessians of the randomly sampled small-gradient instances are multiplied by a factor of to ensure that the overall distribution of gradients remains unbiased.
Note: The reweighting factor ensures that the expected contribution of small-gradient instances matches what would be obtained from the full dataset, maintaining the statistical properties of the gradient boosting algorithm.
- Split Finding:
- The split-finding process (i.e., evaluating possible feature splits and calculating the gain for each) is then performed using the union of all large-gradient instances and the sampled, reweighted small-gradient instances. This dramatically reduces the number of data points considered at each split, leading to much faster training.
The sampling ratio for small-gradient instances is typically set to , where is the sampling ratio for large-gradient instances and is the sampling ratio for small-gradient instances. For example, if and , then 20% of the data with the largest gradients are retained, and 20% of the remaining data with small gradients are randomly sampled and up-weighted.
The Gradient-based One-Side Sampling (GOSS) technique offers several important advantages. First, it greatly improves efficiency by concentrating computational effort on the most informative samples.those with the largest gradients.thereby reducing the amount of data that needs to be processed at each iteration and resulting in faster training times. Second, GOSS maintains high accuracy because it includes all large-gradient instances. Finally, the reweighting of the randomly sampled small-gradient instances guarantees that the calculation of split gain remains an unbiased estimate of what would be obtained if the full dataset were used, preserving the integrity of the learning process.
In summary, GOSS enables LightGBM to scale to very large datasets by reducing the computational burden of split finding while preserving model accuracy and stability.


Mathematical properties
LightGBM maintains the convergence guarantees of gradient boosting, while introducing several efficiency improvements. Its leaf-wise tree growth strategy often results in faster convergence (fewer trees required for a given level of accuracy), though it necessitates careful regularization to avoid overfitting. The histogram-based split finding algorithm in LightGBM has a time complexity of , which is generally more efficient than the complexity of traditional pre-sorted algorithms, especially when the number of bins is much smaller than the number of data points.
In terms of memory usage, LightGBM scales as , rather than , making it well-suited for high-dimensional data. Additionally, the Exclusive Feature Bundling (EFB) technique can reduce the effective number of features by combining mutually exclusive (non-overlapping) features, sometimes halving the number of features in sparse datasets and further improving memory and computational efficiency.
