35. Decision Trees and Random Forests in Python
35.1 Readable Rules from a Decision Tree
Why. Managers like rules they can read: “if complaints ≥ 2 and orders_last_30d < 3 → high churn risk.” Trees speak that language.
What. A decision tree asks yes/no questions on features and ends in a leaf prediction (class or number). You can print the rules — friendlier than a pile of coefs for teaching.
How.
Think in if/else
- Start at the top (root).
- Follow the branch that matches the row.
- Stop at a leaf — that is the prediction.
# Story tree (not fitted yet)
# if complaints >= 2:
# predict churn = 1
# else:
# if orders_last_30d < 3: predict 1
# else: predict 0
print("Trees = stacked if/else on features.")
Ravindra Bagale's Tip
Ek deep tree memorise karte training data — overfitting (Chapter 38). Depth control shik.