Objectives
By the end of this lesson, you will be able to:
- Explain how a decision tree makes a prediction
- Build a decision tree from a small dataset
- Explain why some models are easier to understand than others
Key terms
- Decision tree
- A model that reaches an answer by asking a series of yes-or-no questions about the features.
- Split
- A question in a decision tree that divides the examples into two groups.
- Interpretable
- Describes a model whose reasoning people can follow and explain.
Reading
Twenty questions, written down
A decision tree works like the game of twenty questions. It starts with one question about a feature: does it weigh more than 10 kg? Depending on the answer, it moves to another question, and another, until it reaches an answer at the end of the branch.
The difference from a hand-written rulebook is who chooses the questions. In a learned decision tree, an algorithm looks at the training examples and picks the questions itself.
Choosing good questions
What makes a question good? It separates the examples cleanly. If asking "does it bark?" puts nearly all the dogs on one side and nearly all the cats on the other, it is an excellent question. If asking "is it brown?" leaves both sides just as mixed as before, it is useless.
The algorithm tries the possible questions, measures how well each one separates the labels, picks the best, and then repeats the process on each resulting group. It stops when the groups are clean enough or too small to divide further.
Why readable models matter
You can trace exactly why a decision tree gave an answer by following its branches. That makes it interpretable. If the tree is doing something unfair, such as splitting on a feature it should not use, a person can see it and object.
Many powerful models, including the neural networks in the next lesson, are much harder to read. There is often a trade-off between how capable a model is and how easily people can understand it. When a decision seriously affects someone's life, being able to explain it can matter as much as accuracy.
Try it · Interactive lab
Choose the best first question
Ten pets, five dogs and five cats. A decision tree starts with the question that separates them most cleanly. Find it.
Pick the first question for the tree:
Group activity 25 min
Grow a tree
You will need
- A table of 12 made-up snacks with features (sweet or salty, crunchy or soft, needs a fridge, comes in a wrapper) and a label (healthy choice: yes or no)
- Large paper and markers
- 1
For each feature, count how well it separates the yes and no labels. Which single question gives the cleanest split?
- 2
Draw that question at the top of the paper with two branches.
- 3
For each branch, repeat: among the examples that ended up there, which remaining question separates them best? Stop when a branch holds only one label.
- 4
Test your tree on three new snacks the facilitator provides. Then look at the tree as a whole: does any question seem unfair or silly? Why did the data lead to it?
Discuss
- Q1
Did different groups build different trees from the same data? How can that be?
- Q2
Your tree may have used a question that worked on the 12 examples but makes little sense in general. What does that tell you about small datasets?
- Q3
If a model decided who gets a loan, would you want it to be readable like a tree? What might you give up?
Write your answer to one of the questions. Saved only on this device.
Quick check
Choose an answer to see whether you were right, and why.
Key takeaways
- A decision tree predicts by asking a chain of questions about features.
- The learning algorithm picks the questions that separate the labels best.
- Readable models let people check and challenge decisions.