Blog › Machine Learning Explained

When a model makes a prediction by asking a series of yes-or-no questions, how does a decision tree work? Picture a library that wants to predict whether a borrowed book will come back by its due date. For one new loan, the tree first checks how long the loan lasts. Then, on the branch that this loan takes, it checks whether a reminder is scheduled. Each answer sends the loan to a smaller group of past examples, until the tree reaches a group that supplies the prediction.
Suppose we have 20 made-up records of past library loans. Each record has two features, or pieces of information the model can use: the length of the loan in days and whether a reminder was scheduled when the book was checked out. Each record also has a label, the outcome we want to predict: returned on time or returned late. For a new loan, we know the features at checkout, but we do not know the label.
Of the 20 past loans, 11 came back on time and 9 came back late. A model that always picked the more common label would predict on time for every new loan. The tree can do something more specific. Instead of taking a vote across all 20 records, it first uses the features to decide which group gets to vote.
Is the loan length 14 days or less?
Yes: Predict on time (8 on time, 2 late)
No: Is a reminder scheduled?
Yes: Predict on time (3 on time, 1 late)
No: Predict late (0 on time, 6 late)
The first question is the root, the starting point for every prediction. Each answer leads along a branch to another question or to a leaf, where the tree stops and gives its prediction. The counts at each leaf describe past loans that reached that spot, not new loans whose outcomes are still unknown.
Take a new 21-day loan with no reminder scheduled. To start, ignore the reminder setting. The root asks only whether the loan length is 14 days or less. Since 21 is greater than 14, the answer is no, so the loan goes down the no branch. A loan of exactly 14 days would go the other way, because the question includes the words or less.
This answer narrows the comparison group from 20 past loans to 10. The other 10 had loan lengths of 14 days or less, so they no longer count toward this prediction. Among the 10 remaining records, 3 came back on time and 7 came back late. The majority has flipped: across the whole set, on time was more common, but among longer loans, late was more common.
If the tree stopped here, it would predict late by a vote of 7 to 3. But this branch leads to another question. The on-time majority at the root has not been stored as an earlier vote to add later. It was just a description of the group before any questions were asked.
Now the tree asks whether a reminder is scheduled. The answer is no, so the loan follows the no branch again and reaches a leaf. The group at this leaf consists of six past loans, all of which were late. The tree predicts late for the new loan.
Notice what the second answer rules out. Four of the longer past loans had a reminder scheduled. Three of those were on time and one was late. Once the new loan takes the no branch, none of those four records gets a vote. The leaf represents both answers together: the loan lasts more than 14 days and no reminder is scheduled. It does not represent all loans without reminders.
Try changing just one feature. If the same 21-day loan had a reminder scheduled, it would still take the no branch at the root, but it would take the yes branch at the second question. That leaf predicts on time by a vote of 3 to 1. In contrast, a 10-day loan never reaches the reminder question. Its first answer takes it directly to the leaf with 8 on-time returns and 2 late returns, so its prediction is on time either way.
We drew this tree for the example. When a decision tree is trained from data, a common approach is to try several possible splits at each question and compare how well they separate the labels. For loan length, the model can compare different cutoffs. For the reminder setting, it can split the records into yes and no groups. The scikit-learn guide to decision trees explains how tree algorithms score candidate splits and repeat the process within each branch.
In our example, the reminder question separates the longer loans into a group that mostly came back on time and a group that came back late every time. But six late returns do not prove that the next loan will be late. They also do not prove that scheduling a reminder would cause a book to come back on time. The tree found a pattern in these records. Testing it on loans it did not train on would help show whether the pattern holds up for prediction.
On paper, write the condition and the answer at each step: 21 days is greater than 14, so no; no reminder is scheduled, so no; the leaf predicts late. That short trace shows why the 8 on-time returns on the other side of the root did not affect the result. For more practice making your reasoning easy to check, see our guide to showing your work on machine learning problems and the IMLC learning resources.
As a final paper exercise, trace a 14-day loan with no reminder. If you find yourself checking the reminder setting, go back to your first answer. The 14-day loan has already reached a leaf.
Does every prediction use every feature?
No. A tree only checks the features on the path the example takes. In this tree, a 14-day loan reaches a leaf without checking the reminder setting.
Can a leaf have both on-time and late returns?
Yes. In this example, a leaf predicts the more common label among the past loans that reached it, even if some had the opposite outcome.
Does six out of six mean the next book will be late?
No. It means all six training loans at that leaf came back late. A new loan can still have a different outcome.
About the International Machine Learning Competition: an online machine learning competition for high school students from around the world. Qualification Round 2026: submissions are open until Sunday, 13 December 2026. How the rounds work