Lessons › Chapter 6: Trees and ensembles
Decision trees
A decision tree makes a prediction by asking a series of yes-or-no questions, like the game twenty questions. It starts with one question at the top.
Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.
Start the interactive lessonStep by step
Explain it to the regulator
The banking regulator asks why each loan was declined. Maya needs a model a person can read.
A game of twenty questions
A decision tree makes a prediction by asking a series of yes-or-no questions, like the game twenty questions. It starts with one question at the top.
Each answer opens a branch
Depending on the answer, you follow a branch to the next question. Different people take different paths through the tree.
Leaves give the answer
When there are no more questions, you reach a leaf. It holds the final answer: approve or decline. Learning a tree means choosing which questions to ask, and in what order, so the leaves come out as clean as possible.
Questions carve up the map
On a map of the data, each question is a straight cut, either across or up and down. Together the cuts make boxes, each with its own answer. That’s why tree boundaries look like steps.
In real life: loan and insurance rules
Lenders and insurers like decision trees because you can read them: every decision can be traced to a few plain questions. That makes it easier to explain a “no” to a customer or a regulator.
Quick check: Where does a decision tree give its final answer?
- At the top question
- At a leaf (correct)
- On the branches
You follow branches down from the top question until you reach a leaf, which holds the answer.
Pseudocode
ask: is income > 40k?
yes → ask: any missed payments?
yes → decline
no → approve
no → ask: has a guarantor?
yes → approve
no → decline
# learning = choosing the best questions, in the best order
Key terms
- leaf
- An end point of a decision tree. It holds the final answer.
Build it: Loan decisions with trees and forests (35 min, runs in your browser)
See the project