How is feature importance calculated for GradientBoostingClassifier
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
In scikit-learn's GradientBoostingClassifier, the default feature importance is based on how much each feature reduces the split criterion across the trees in the ensemble. In other words, features that produce larger weighted impurity reductions across many splits receive higher importance scores.
The Core Idea: Total Reduction in Impurity
Each decision tree in gradient boosting splits nodes using a criterion such as Gini impurity or log-loss-related improvement, depending on the configuration. Whenever a feature is used to split a node, that split reduces impurity by some amount.
The importance calculation accumulates those reductions for each feature across all trees, weighted by how many samples reach the split.
A simplified mental model is:
After summing across the ensemble, scikit-learn normalizes the values so they add up to 1.0.
Example in scikit-learn
Here is a small runnable example:
model.feature_importances_ is the impurity-based importance vector. The higher the value, the more that feature contributed to split quality across the boosted trees.
Why the Scores Are Not Just Split Counts
It is not enough for a feature to appear often. A feature used in many weak splits may matter less than a feature used in a few very strong splits near the top of the trees.
That is why importance reflects the quality of the splits, not only their count. Splits that affect many samples and create large impurity reductions usually matter more.
This is also why importance depends on the full fitted model rather than on any simple property of the raw dataset.
Look at Permutation Importance Too
Impurity-based importance is fast and convenient, but it has limitations. A useful comparison is permutation importance, which measures how much model performance drops when a feature is shuffled.
Permutation importance is slower, but it often gives a more intuitive view of predictive importance because it asks: "How much does the model rely on this feature for its actual predictions?"
Important Limitations
Impurity-based importance can be biased toward:
- Features with many possible split points
- Continuous features
- Correlated features that share predictive signal
For example, if two features contain nearly the same information, the model may split importance between them in a way that makes each individual score look smaller than expected.
That does not mean the features are unimportant. It means the model has multiple ways to capture similar signal.
Common Pitfalls
The biggest mistake is interpreting feature importance as causation. These scores describe how the fitted model used the features, not whether the features cause the target.
Another issue is assuming the numbers are stable across different random seeds, data splits, or model hyperparameters. Because gradient boosting is a learned model, importance scores can shift when the training setup changes.
Developers also often compare impurity-based scores across different models as though they were directly interchangeable. They are mainly meaningful within the context of a specific fitted model.
Finally, do not rely on a single importance method when interpretation matters. It is often worth comparing impurity-based importance, permutation importance, and domain knowledge together.
Summary
- '
GradientBoostingClassifiercomputes default feature importance from total weighted impurity reduction across splits.' - The scores are aggregated over all trees and normalized to sum to
1.0. - Importance reflects split quality and sample weight, not just how often a feature appears.
- Correlated or high-cardinality features can distort impurity-based importance.
- Use permutation importance as a useful second view when interpretation matters.
Related reading
- How is Hard Sigmoid defined
- How is Nesterov's Accelerated Gradient Descent implemented in Tensorflow?
- How is teacher-forcing implemented for the Transformer training?
- How is tf.summary.tensor_summary meant to be used?
- How is the categorical_crossentropy implemented in keras?
- How is the Keras Conv1D input specified? I seem to be lacking a dimension
- How is the R2 value in Scikit learn calculated?
- How is the smooth dice loss differentiable?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.