All lessons in Machine Learning Engineering: Reliable Predictive Models
Impurity Importance and Its Biases
Compute sample-weighted tree contributions and investigate high-cardinality distractors.
30 minutes · Members lesson · preview
What you will learn
- Compute a feature's impurity importance from node class counts by summing sample-weighted impurity decreases and normalizing across features.
- Explain why a many-valued or noisy feature can receive inflated training-set importance and why that number is not a held-out scoring metric.
- Design a check that compares impurity importance against permutation importance and ablation on unseen rows before trusting a ranking.
The parcel carrier's dispatch model is a random forest trained on five features: dispatch_load, load_proxy, weather_risk, weekend and noise_code. The operations lead asks a reasonable question: which of these did the trees actually use? The number most people reach for first is impurity importance, the quantity scikit-learn exposes as feature_importances_. It is cheap, it is computed as a by-product of training, and it is frequently misread. This lesson builds it by hand from node counts so you can see what it measures, then looks at two ways it misleads: distractor features with many distinct values, and the gap between training impurity and the validation log loss you actually use to select a model.