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$.
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).
4# Pruned decision tree for business interpretability
5dt = DecisionTreeClassifier(
6 max_depth=4,
7 min_samples_leaf=25,
8 criterion='gini',
9 random_state=42
10)
11dt.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:
1import pandas as pd
2
3feat_importance = pd.DataFrame({
4'Feature': X_train.columns,
5'Importance': dt.feature_importances_
6}).sort_values(by='Importance', ascending=False)
7
8print(feat_importance)
4. Visualizing the Tree for Executive Presentations
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
12-Month Data Analysis Mastery Program
Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)
Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.