✦ New Age Learning 🔍
Home › Library › AI for New Learner- Senior 2 › Chapter 4: Decision Trees & Random Forests

📖 Chapter 4 of 13 · AI for New Learner- Senior 2 · Class 10

Chapter 4: Decision Trees & Random Forests

In this chapter

  • Inaaya from Thiruvananthapuram — building an explainable medical screening AI.
  • Decision Trees: AI that decides like a doctor — if-then-else chains.
  • Random Forests: combine many trees, dramatically better accuracy.
  • Why explainable AI matters in healthcare, banking, and law.
  • Real sklearn code: train, visualise, and explain your model’s choices.

The Big Idea

Decision trees explain themselves. Unlike neural networks (which are mostly black boxes), you can ASK a tree ‘why did you decide YES?’ and it will trace the path: ‘Because age > 30 AND blood pressure > 140 AND sugar > 200.’ This is GOLD in healthcare, banking, and any field where you must DEFEND a decision. Niramai (Indian cancer AI) uses tree-based models for exactly this reason.

Did you know?

Random Forest was invented by Leo Breiman in 2001. Today XGBoost and LightGBM (modern forest variants) win more Kaggle competitions than ANY neural network. Most Indian banks use forest models — not deep learning — for credit decisions because they are explainable.

Builder Profile: Inaaya

Thiruvananthapuram, KL · age 15

Inaaya’s decision tree screens diabetes risk and can explain every verdict by tracing its if-then path.

Inaaya’s father is a doctor at SCT Institute. He shared a challenge: “Can AI help nurses screen for diabetes risk in our village outreach camps? But it must explain itself. If the AI says HIGH RISK, the patient and nurse must understand WHY.”

Inaaya tried a neural network first. 87% accuracy. But when she asked the model WHY a patient was flagged, it shrugged. Just numbers. Useless to a nurse holding a clipboard.

She switched to a Random Forest. 84% accuracy — 3% lower! But the model could explain EVERY decision: “This patient is HIGH RISK because: age=52, BMI=31, fasting glucose=145, family history=YES. These 4 factors had the biggest weight.” The nurse could now have a real conversation. Her father’s hospital is testing the model in 3 camps. Accuracy was less. Trust was more. Inaaya learned: in healthcare, EXPLAINABLE beats ACCURATE.

How a tree decides

A decision tree is if-then-else, all the way down. It starts at a root question (‘Glucose > 140?’). If YES, it may reach a leaf (‘HIGH RISK’). If NO, it asks another question (‘Age > 45?’) and branches again until it reaches a verdict. A Random Forest takes this further: one tree can overfit (memorise), so a forest of 100 trees — each trained on a random subset of data and features — votes on the final answer. Wisdom of the crowd, applied to AI. Almost always more accurate than a single tree, slower to train but still seconds for most datasets.

💻 CODE LAB Random Forest — Train + Feature Importance

import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split

df = pd.read_csv('diabetes_screening.csv')
X = df[['age', 'bmi', 'glucose', 'bp', 'family_history']]
y = df['risk_high']

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42)

model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
print('Accuracy:', model.score(X_test, y_test))

# EXPLAIN: which feature mattered most?
for feature, importance in zip(X.columns, model.feature_importances_):
    print(feature, round(importance, 2))
# glucose: 0.42  bmi: 0.21  age: 0.18  bp: 0.12  family_history: 0.07

Solved illustrations

1. What is the difference between a tree and a forest?

Show answer

Answer: A single Decision Tree is one set of if-then-else rules. A Random Forest is 100+ trees, each trained on a random sample of the data, that VOTE together. Forests are usually more accurate but slightly slower.

2. What does ‘n_estimators=100’ mean?

Show answer

Answer: Number of trees in the forest. 100 is a common starting point. More trees = slightly better accuracy + much more training time. Diminishing returns after about 200-500.

3. How do I ‘see’ a single tree from sklearn?

Show answer

Answer: from sklearn.tree import export_text, then print(export_text(model.estimators_[0])). This prints the actual if-else rules of the first tree. Great for understanding what your forest learnt.

4. Random Forest vs neural network — which to choose?

Show answer

Answer: Tabular data (rows + columns with names)? Forest usually wins. Images, audio, text? Neural networks. This is a real rule used at Indian AI companies — don’t reach for deep learning when a forest will do.

5. What is ‘feature_importances_’?

Show answer

Answer: A list of how much each input column influenced the model’s decisions. Bigger = more important. Use it to remove useless features from your model — simpler is better.

Questions — Chapter 4

A. Fill in the blanks

  1. A Decision Tree is just a chain of -then- rules.
  2. A Random combines many trees into one prediction.
  3. n_estimators=100 means the forest has trees.
  4. To EXPLAIN a forest, look at model.importances_.
  5. Tree-based models are common in (industry) because they explain decisions.

B. Short answers

  1. Why is EXPLAINABILITY important in healthcare AI? Give 2 reasons.
  2. When would you choose a single tree over a forest?
  3. List 3 problems where a Random Forest would beat a Neural Network.
  4. Write 4 lines of sklearn code to train and score a Random Forest.
  5. Inaaya gave up 3% accuracy for explainability. Was she right? Argue your view.

Ship-It Challenge

Train RandomForestClassifier on any dataset. Print the top 3 features by importance.

Check your understanding — Chapter 4

Tap an answer to check it instantly. These are for practice — nothing is saved or sent.

Q1. What is the difference between a decision tree and a random forest?

  1. Nothing
  2. A tree is one set of if-then rules; a forest is 100+ trees, each on a random sample, that vote together
  3. A forest has no trees
Show answer

B. A tree is one set of if-then rules; a forest is 100+ trees, each on a random sample, that vote together

Q2. Why is explainability important in healthcare AI?

  1. It isn't
  2. So a nurse and patient can understand WHY the AI flagged high risk — you can trace a tree's exact path
  3. To make it run faster
Show answer

B. So a nurse and patient can understand WHY the AI flagged high risk — you can trace a tree's exact path

Q3. Random Forest vs neural network — which for tabular data?

  1. Always neural networks
  2. For tabular data (rows and named columns), a forest usually wins; use neural nets for images, audio and text
  3. Always avoid both
Show answer

B. For tabular data (rows and named columns), a forest usually wins; use neural nets for images, audio and text

Q4. What is 'feature_importances_' used for?

  1. Sorting rows
  2. A list of how much each input column influenced the model — use it to drop useless features
  3. Saving the model
Show answer

B. A list of how much each input column influenced the model — use it to drop useless features

All chapters in AI for New Learner- Senior 2

  1. Chapter 1: Where You Are Now — The ML Lifecycle
  2. Chapter 2: From Idea to Dataset
  3. Chapter 3: Linear Models — The Workhorses
  4. Chapter 4: Decision Trees & Random Forests
  5. Chapter 5: Neural Networks Demystified
  6. Chapter 6: Evaluation — Does It Actually Work?
  7. Chapter 7: Indian Datasets & Real Problems
  8. Chapter 8: Deploy Your AI — Get a Public URL
  9. Capstone Build-It Projects
  10. Final Book Exam
  11. AI / ML / Python Glossary
  12. Career & College Pathways
  13. Series Completion Diploma

Practise for Class 10