Ravindra BagaleCourses & study guides मराठी Track your progress

35. Decision Trees and Random Forests in Python

Data Science

35.2 One Tree vs Random Forest

Why. One tree is easy to read but can be unstable. A random forest grows many trees on random row/feature slices and averages their votes.

What. Forest ≈ “committee of trees.” Usually stronger and less sensitive to one weird row; harder to draw on a whiteboard than a single small tree.

How.

When to prefer which

  1. Need explainable classroom rules → start with one shallow tree.
  2. Need better accuracy on tabular India ops data → try RandomForest.
  3. Still split train/test either way.
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier

# Same X, y idea as Chapter 34 — forest is many trees voting
print(DecisionTreeClassifier)
print(RandomForestClassifier)

Ravindra Bagale's Tip

A random forest is a group of many decision trees that combine their answers. One tree is easy to explain, while a forest usually gives better results. Be ready to explain this difference in interviews.