Decision Trees & Feature Importance Interpretation0%

Decision Trees & Feature Importance Interpretation

Beginner12 min read•Updated: Jul 11, 2026
Study Materials

Decision Trees & Feature Importance Interpretation

Decision Trees are non-parametric supervised learning models that partition feature space into rectangular regions using hierarchical if-then rules. Because they mimic human logical reasoning and automatically capture non-linear relationships and feature interactions, decision trees are one of the most interpretable tools in a business analyst's toolkit.


1. How Decision Trees Split: Gini Impurity vs Entropy

At each internal node, the decision tree algorithm tests all available features and numerical thresholds to find the split that maximizes information gain (reduction in impurity):

Gini Impurity

$$Gini = 1 - \sum_{i=1}^{C} p_i^2$$

  • A pure node (100% class A) has $Gini = 0.0$.
  • An evenly mixed binary node (50% A, 50% B) has maximum impurity $Gini = 0.50$.

Entropy & Information Gain

$$Entropy = -\sum_{i=1}^{C} p_i \log_2(p_i)$$


2. Preventing Overfitting: Regularization Hyperparameters

An unconstrained decision tree will continue splitting until every training leaf contains exactly 1 sample, memorizing noise and achieving 100% training accuracy but abysmal test accuracy.

Critical Hyperparameters:

  • max_depth: Limits how deep the tree can grow (e.g., 3 to 6 levels for interpretability).
  • min_samples_split: Minimum samples required to split an internal node.
  • min_samples_leaf: Minimum samples required to exist at a leaf node (e.g., 20-50).
Python
from sklearn.tree import DecisionTreeClassifier, export_text, plot_tree
import matplotlib.pyplot as plt
 
# Pruned decision tree for business interpretability
dt = DecisionTreeClassifier(
max_depth=4,
min_samples_leaf=25,
criterion='gini',
random_state=42
)
dt.fit(X_train, y_train)

3. Extracting and Visualizing Feature Importance

Decision trees calculate MDI (Mean Decrease in Impurity), reflecting the total weighted reduction in Gini impurity brought by each feature across all splits:

Python
import pandas as pd
 
feat_importance = pd.DataFrame({
'Feature': X_train.columns,
'Importance': dt.feature_importances_
}).sort_values(by='Importance', ascending=False)
 
print(feat_importance)

4. Visualizing the Tree for Executive Presentations

Python
plt.figure(figsize=(20, 10))
plot_tree(
dt,
feature_names=X_train.columns,
class_names=['Retained', 'Churned'],
filled=True,
rounded=True,
fontsize=10
)
plt.title("Executive Decision Tree: Customer Churn Drivers")
plt.show()

Interactive Quiz

Multiple Choice Questions

Question 1
What is the value of the Gini Impurity for a completely pure leaf node where all observations belong to the same class?
Question 2
Why does an unconstrained decision tree with unlimited max_depth and min_samples_split=2 typically suffer from severe overfitting?
Question 3
Which hyperparameter prevents overfitting by ensuring that every leaf node contains at least a specified minimum number of samples?
Question 4
How does feature scaling (e.g., standardizing between 0 and 1) affect decision tree splits?
Question 5
What does Feature Importance in a Scikit-Learn Decision Tree measure?

Next Lesson

K-Means Clustering & The Elbow Method

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext