Skip to content
datarekha
Machine Learning Hard Asked at GoogleAsked at MetaAsked at UberAsked at AirbnbAsked at Booking.com

What are the key algorithmic differences between XGBoost and LightGBM?

The short answer

XGBoost normally grows trees depth-wise and supports exact, approximate, and histogram split finding, while LightGBM normally grows trees leaf-wise and uses histogram split finding. LightGBM also offers GOSS and EFB optimizations, although modern XGBoost commonly uses its own histogram algorithm.

How to think about it

Short answer: XGBoost normally grows trees depth-wise, or level-wise, while LightGBM normally grows them leaf-wise, or best-first. XGBoost supports exact, approximate, and histogram-based split finding; LightGBM is built around histograms and adds GOSS and EFB optimizations for reducing training work.

Why the difference matters

Both libraries implement gradient-boosted decision trees: an ensemble in which each new tree tries to correct the errors left by the previous trees.

At every candidate split, the libraries estimate how much the split would improve the training objective. They use the gradient, which says how the current prediction should move, and the Hessian, which measures the local curvature of the loss. If G is the sum of gradients in a leaf and H is the sum of Hessians, a simplified L2-regularised leaf weight is:

w* = -G / (H + lambda)

A split is useful when the combined score of its two children is sufficiently better than the parent score. This is why the libraries do not simply choose the feature with the strongest correlation. They choose the split with the best predicted reduction in the regularised objective.

The main difference is what happens after several legal splits are available.

Tree growth: depth-wise versus leaf-wise

Suppose a root split creates two leaves, A and B. The best available split in A has a gain of 40, while the best split in B has a gain of 3. Gain here means predicted reduction in the regularised training loss.

After splitting A, imagine the available gains are:

Available leafBest split gain
A-left18
A-right12
B3

XGBoost’s default depthwise policy works through the tree by depth. It considers the eligible leaves at the current level before moving to deeper levels. A and B are at the same depth, so both may be expanded before XGBoost works on descendants. The result is usually a more depth-controlled, relatively balanced tree, although constraints can prevent some leaves from splitting.

LightGBM’s leaf-wise policy chooses the leaf with the largest current gain. In this example it can split A-left with gain 18, then A-right with gain 12, while leaving B untouched. One branch becomes deeper because it contains a concentrated pattern that the model can exploit.

That can reduce training loss quickly. It can also memorise a small group of rows quickly. A rare customer segment, an unusual transaction pattern, or an accidental identifier can become a very attractive deep branch.

For LightGBM, num_leaves limits the total number of leaves. min_data_in_leaf, also called min_child_samples in its Python API, prevents leaves from becoming too small. max_depth can impose an additional depth limit.

Common trap: lowering learning_rate does not make an overly complex tree simple. It shrinks each tree’s contribution, but a tree with 255 leaves can still discover highly specific patterns. Control the structure with num_leaves, minimum leaf size, depth, split-gain thresholds, subsampling, and early stopping.

XGBoost is not permanently depth-wise. Setting grow_policy="lossguide" makes it choose leaves by loss reduction, which makes the comparison much less absolute. The usual interview answer assumes XGBoost’s default depth-wise policy.

Split finding: exact, approximate, and histogram methods

Finding a split means finding a feature and threshold that divide the rows profitably.

XGBoost has three important tree-building modes:

  • exact examines thresholds from sorted feature values. It is accurate but expensive, especially with many rows or distinct values.
  • approx uses approximate quantile information to select candidate thresholds.
  • hist maps feature values to bins, aggregates gradients and Hessians per bin, and evaluates candidate splits from those aggregates.

The histogram method is the practical choice for many modern XGBoost workloads. Therefore, “XGBoost uses exact splits and LightGBM uses histograms” is an outdated answer.

LightGBM’s standard numerical-feature path is histogram-based. Its usual max_bin default is 255, although the value is configurable. Saying that LightGBM always uses 256 bins is wrong: the number is a parameter, and categorical or special feature handling can follow different paths.

Why do histograms help? With 1,000,000 rows and 200 features, a raw split search may encounter roughly 200,000,000 feature values. A histogram reduces each feature to a bounded set of bins, then reuses cumulative gradient and Hessian sums to score candidate thresholds. This reduces split-evaluation cost and memory pressure.

The trade-off is quantisation. If a useful boundary is lost when values are placed in the same bin, the tree cannot recover that exact threshold. Increasing max_bin can preserve more resolution, but costs more memory and computation. A very small max_bin may hurt a feature whose predictive signal depends on narrow numeric ranges.

GOSS and EFB

LightGBM is also known for two dataset-level optimisations.

Gradient-based One-Side Sampling, or GOSS, keeps rows with the largest absolute gradients and randomly samples rows with small gradients. Large gradients usually indicate rows the current model is getting badly wrong, so they carry more immediate learning signal.

For a concrete example, take 1,000,000 rows. Keep the top 20 percent by gradient magnitude and randomly retain 10 percent of the remaining rows. That leaves:

  • 200,000 high-gradient rows
  • 80,000 sampled low-gradient rows
  • 280,000 rows processed instead of 1,000,000

The sampled low-gradient group is reweighted. With these proportions, its multiplier is (1 - 0.2) / 0.1, or 8, so the smaller sample better represents the rows it came from.

GOSS can reduce histogram-construction work, but it is not free. Gradient magnitude can also reflect label noise or outliers. Sampling those rows aggressively may increase variance or make training less stable. Standard LightGBM GBDT training does not automatically mean GOSS is being used; it is a separate boosting choice.

Exclusive Feature Bundling, or EFB, targets sparse features that are rarely non-zero together. Imagine 200 features: 20 dense measurements and 180 one-hot columns representing a plan code. Each row has at most one active plan column. EFB can bundle those 180 sparse columns into a much smaller number of feature groups, reducing the number of histograms that must be built.

EFB reduces effective feature count, not row count. It is most useful for wide sparse data. If supposedly exclusive features frequently appear together, conflicts reduce the possible bundling and the speed benefit.

A concrete configuration comparison

Here is a reasonable starting point for comparing the standard tree policies:

xgb_model = xgb.XGBClassifier(
    n_estimators=1000,
    learning_rate=0.03,
    tree_method="hist",
    grow_policy="depthwise",
    max_depth=6,
    max_bin=255,
    reg_alpha=0.1,
    reg_lambda=1.0,
)

lgb_model = lgb.LGBMClassifier(
    n_estimators=1000,
    learning_rate=0.03,
    boosting_type="gbdt",
    num_leaves=63,
    min_child_samples=20,
    max_bin=255,
    reg_alpha=0.1,
    reg_lambda=1.0,
)

The settings are not equivalent. A complete binary tree with XGBoost max_depth=6 can have up to 64 leaves, while LightGBM num_leaves=63 allows up to 63. But LightGBM can arrange those leaves in a much deeper, more asymmetric shape.

Also, XGBoost’s min_child_weight is based on the sum of Hessians, not simply the number of rows. LightGBM’s min_data_in_leaf is a row-count constraint. Setting both parameters to 20 would not impose the same restriction.

Both libraries support L1 and L2 leaf regularisation. It is incorrect to present L1 and L2 as an XGBoost-only feature. Parameter names and the exact interaction with other constraints differ, so compare behaviour rather than matching names mechanically.

The senior-level answer: it depends on the workload

LightGBM is often a strong candidate for very large, wide, or sparse tabular data because histogram training, leaf-wise growth, GOSS, and EFB can reduce computation. XGBoost with tree_method="hist" can also be highly competitive. Hardware, sparsity, feature cardinality, objective, threading, categorical handling, and parameter choices all matter.

For smaller data, depth-wise growth can be easier to control and debug. That does not make XGBoost automatically more accurate or LightGBM automatically unsafe. A constrained LightGBM model may generalise well; an unconstrained XGBoost model can overfit just as thoroughly.

For a fair benchmark, use the same train-validation split, target definition, evaluation metric, feature representation, random-seed policy, and early-stopping rule. Measure validation quality, wall-clock training time, peak memory, prediction latency, and model size. Comparing “500 trees” is not enough when one library’s trees are much more complex.

A failure mode you can recognise

Suppose a churn dataset has 50,000 rows. You set LightGBM to num_leaves=255 and min_child_samples=5. After 200 trees, training AUC reaches 0.99, validation AUC stalls at 0.74, and validation loss rises while training loss keeps falling.

That pattern is the first symptom of structural overfitting, not evidence that the learning rate is too high. Reduce num_leaves, increase the minimum leaf size, consider a depth limit, use feature or row subsampling, and stop on a validation set. Also inspect high-cardinality identifiers; a customer ID can be a remarkably efficient route to a bad model.

What they will ask next

Is LightGBM always faster than XGBoost?

No. Both can use histogram training, and XGBoost’s histogram implementation may be faster on some hardware or workloads. Benchmark the complete pipeline, including data conversion, training, validation, and prediction.

Can XGBoost grow trees leaf-wise?

Yes. XGBoost’s grow_policy="lossguide" selects the leaf with the greatest loss change, subject to its leaf and depth constraints. The depth-wise-versus-leaf-wise contrast describes the common defaults, not an immutable library boundary.

How would you control LightGBM overfitting?

Start with num_leaves and min_data_in_leaf, then consider max_depth, minimum split gain, row or feature subsampling, L1 or L2 regularisation, and early stopping. If using a depth limit, keep num_leaves no greater than 2^max_depth; otherwise the two limits can fight each other.

Say this in the interview

“XGBoost usually grows trees depth-wise and offers exact, approximate, or histogram split finding, while LightGBM grows leaves best-first with histogram training plus optimisations such as GOSS and EFB; the practical choice depends on data scale, sparsity, regularisation, and a fair benchmark rather than a blanket speed claim.”

Learn it properly XGBoost, LightGBM, CatBoost

Keep practising

All Machine Learning questions

Explore further