Decision tree

Supervised · Classification & regression A decision tree makes a prediction by asking a series of yes/no questions, like a flowchart. At each step it picks the question that best separates the data into clear groups. The final boxes, called leaves, hold the answer.

Everyday analogy

The game of 20 Questions: "Is it an animal? Does it live in water? Is it bigger than a cat?" Each good question cuts down the possibilities fast.

Example

Used for: loan approval, medical triage checklists, routing customer-service tickets, predicting which products a customer may need.

Income > ₹50k?Yes → Credit score > 700?Yes → ✅ ApproveNo → 🔎 ReviewNo → Existing loan?Yes → ❌ DeclineNo → 🔎 Review
A decision tree asks a series of yes/no questions until it reaches an answer.

A decision tree for a loan application

Monthly income above ₹50,000?
Yes ↓
Already has 2+ loans?
Yes ↓Manual review
No ↓Approve
No ↓
Has a guarantor?
Yes ↓Manual review
No ↓Decline

A simplified illustration. A real tree learns its questions and thresholds from past data.

How it works, step by step

  1. Start with all the training examples together.
  2. Try every possible question ("income above X?", "has a guarantor?") and measure how well each one splits the data into purer groups. Common measures are called Gini impurity and entropy: they score how mixed-up a group is.
  3. Pick the best question and split the data into branches.
  4. Repeat for each branch with the remaining data.
  5. Stop when the groups are pure enough or the tree reaches a set depth. Each final leaf gives the answer.

Worked example

From 1,000 past loans, the tree finds that income is the single best first question. Among high earners, the number of existing loans best separates good and bad repayers. Among lower earners, having a guarantor matters most. The result is the tree above.

✓ Good for

  • Very easy to explain: you can show the exact path to any decision
  • Handles numbers and categories with little preparation
  • Fast to train and use

⚠ Watch out for

  • A deep tree can memorise the training data (overfitting)
  • A small change in the data can produce a very different tree
  • Usually less accurate than a random forest or boosting

Try it yourself

About 10 min

Build a tree on paper

  1. Decide should I order food tonight? with yes/no questions: tired? groceries at home? budget?
  2. Draw the tree with an answer at each leaf.
  3. Test it on three different evenings.

What you should see: A decision tree is a flowchart learned from data.

Use any free AI chatbot (ChatGPT, Claude, Gemini or Copilot). Never paste private or confidential information.

Build it for real · guided projectYour first machine learning model: predict house pricesAbout 75 min · Copy-paste code · step by step
Test what you learned

Take a quick quiz, or look up any word in the glossary.