Excellent question. This is a very common observation, and it points to the core architectural differences between the two libraries.
The primary reason your XGBoost model is much larger than your CatBoost model is due to the fundamental difference in how they build and store their decision trees.
Here’s a breakdown of the key factors, from most to least impactful.
1. The Core Reason: Symmetric vs. Asymmetric Trees
This is the single biggest contributor to the size difference.
-
CatBoost: Oblivious (Symmetric) Trees
CatBoost uses oblivious decision trees. This means that for a given tree, all nodes at the same level use the exact same feature and split condition. The tree is perfectly symmetrical.
- How it's stored: To save a tree, CatBoost only needs to store one split condition (e.g.,
feature_5 > 10.2) for each level of the tree, plus the final leaf values.
- Size Impact: This is incredibly memory-efficient. For an 8-level deep tree, it only needs to store 8 split rules, not one for every single node.
[image: CatBoost Oblivious Tree] open
(Notice how Level 1 always splits on X1, and Level 2 always splits on X2)
-
XGBoost: Asymmetric (Depth-wise or Leaf-wise) Trees
XGBoost builds standard decision trees. Each node is split independently based on the best possible gain at that point. A node on the left side of the tree can split on a completely different feature than a node at the same level on the right side.
- How it's stored: To save a tree, XGBoost must store the split feature, split value, and child node pointers for every individual internal node.
- Size Impact: This requires vastly more information. For an 8-level deep tree, there could be up to 2⁸-1 = 255 internal nodes, each needing its own split information stored.
[image: XGBoost Asymmetric Tree] open
(Notice how nodes at the same level can split on different features, like X1 and X2 at Level 1)
Analogy: Filing Cabinets
- CatBoost is like a filing cabinet with simple, uniform dividers. The first drawer is always "A-M" vs "N-Z". The second drawer is always "Jan-Jun" vs "Jul-Dec". The instructions are short: "Level 1: Split by alphabet. Level 2: Split by month."
- XGBoost is like a filing cabinet with highly customized folders. The first folder might be "Urgent Client A," while another at the same level is "Internal Memos Q3." The instruction manual (the model file) has to be much longer to describe every single custom folder label.
2. Handling of Categorical Features
This is another significant factor, especially if your dataset has many categorical columns.
-
CatBoost: Native & Efficient
CatBoost has a world-class, built-in system for handling categorical features (using target statistics, permutations, etc.). It processes them internally without you needing to preprocess them. This keeps the feature space small.
-
XGBoost: Traditionally Requires One-Hot Encoding
Until recent versions, the standard way to use categoricals in XGBoost was to one-hot encode them. If you have a feature City with 100 unique values, one-hot encoding creates 100 new binary features. This explodes the number of features the model has to consider, leading to more potential splits and a much larger model.
- Note: Newer XGBoost versions (1.6+) have experimental support for categorical features (
enable_categorical=True). However, CatBoost's implementation is still often considered its core strength and is deeply integrated with its oblivious tree structure.
3. Quantization of Numerical Features (Binning)
Both libraries convert continuous numerical features into discrete bins to speed up training. This is a core part of the hist tree-building method in XGBoost and is fundamental to CatBoost.
- When a model is saved, it stores the split points based on these bin indices (e.g., "split at bin 57") rather than the original float values. This makes the model more compact.
- While both do this, the effect is magnified by CatBoost's oblivious tree structure. Storing a single bin index per level is far more efficient than storing a bin index for every node in XGBoost's larger, asymmetric trees.
How to Control Model Size (Especially in XGBoost)
If model size is a critical constraint, here's what you can do:
-
Use tree_method='hist' in XGBoost: This is the most important step. The older exact method can result in larger models. hist is now the default in newer versions, but it's good to be explicit. It enables the quantization mentioned above.
-
Reduce Tree Complexity:
max_depth: Lower this value. This is the most direct way to reduce the size of each tree.
n_estimators: Lower the number of trees in the forest. The model size scales linearly with this parameter.
max_leaves: You can use this instead of max_depth to control complexity. It allows the tree to grow leaf-wise (finding the best split anywhere, not just at the deepest level) but limits the total number of leaves.
-
Increase Pruning:
gamma (or min_split_loss): Increase this value. It sets a minimum loss reduction required to make a split. A higher value leads to more pruning and simpler trees.
min_child_weight: Increase this value. It prevents the model from learning relationships that are only present in very small, specific groups of data, leading to simpler trees.
Summary (TL;DR)
| Feature | XGBoost | CatBoost | Impact on Size |
|---|
| Tree Structure | Asymmetric (depth-wise) | Symmetric (oblivious) | Massive. CatBoost's structure is inherently far more compressible. |
| Categorical Data | Requires One-Hot Encoding (traditionally) | Native, internal handling | High. OHE explodes feature count, making XGBoost models larger. |
| Parameters | Flexible, many tuning knobs (max_depth, gamma) | Similar knobs (depth, etc.) | High. Both can be tuned, but XGBoost's defaults might lead to a larger starting model. |
Your observation is spot on and highlights the clever engineering trade-offs the CatBoost team made to optimize for memory, speed, and ease of use, especially on datasets rich with categorical features.