What is a decision tree?
Last updated: 2026-11-23
A decision tree is a model that predicts by asking a series of yes-or-no questions about the inputs, one question at each branch, until it reaches a leaf that holds the answer. It is learned from data: the training step chooses each question so that each group it creates is as uniform in its labels as possible.
Start learning No account needed
If you picture a flowchart that sorts examples into groups, you have the idea. If you want the statistics a model like this rests on, learn statistics on your own covers the basics.
1. The pieces
The scikit-learn documentation describes decision trees as a non-parametric supervised learning method, used for classification and regression, that learns simple decision rules from the features of the data. Supervised means every training example comes with its label, such as pass or fail. A node is one question, a branch is one answer to it, and a leaf is a node that stops asking and gives a prediction. For classification, the documentation says a leaf predicts the proportion of each class among the training examples that reached it.
The learning step splits the data at a node into a left part and a right part. Each candidate split is a feature and a threshold, and the documentation says the thresholds tried are the midpoints between sorted, distinct feature values. To score a split, the tree measures how mixed each part is with an impurity function. The documentation lists two common ones for classification. Gini impurity is the sum over classes of p times (1 minus p), where p is the share of the class in the node, and entropy is minus the sum of p times log p. Both are 0 for a node where every example has the same label. A split is scored by the weighted average of the two parts' impurities, where each part is weighted by its share of the examples, and the default splitter picks the candidate with the lowest score by a greedy exhaustive search over all features and thresholds. It then repeats the same procedure inside each part.
2. A worked example: ten students, pass or fail
Ten students each have two facts: the hours they studied (1 to 10) and whether they attended a review session. The numbers are made up for this page. Students who studied 1, 2, 3 or 5 hours and skipped the review failed; the student with 4 hours attended the review and passed; the students with 6, 7, 8, 9 and 10 hours passed. That is 6 passes among 10 students. For two classes, the Gini impurity is 2 × p × (1 − p), so the starting node has 2 × 0.6 × 0.4 = 0.48.
Try three candidate splits at the root. Splitting at hours ≤ 3.5 gives a left part of 3 students with no passes (impurity 0) and a right part of 7 students with 6 passes (impurity 0.245), so the weighted score is 7/10 × 0.245 = 0.171. Splitting at hours ≤ 5.5 gives a left part of 5 students with 1 pass (impurity 0.32) and a right part of 5 students who all passed (impurity 0), so the score is 5/10 × 0.32 = 0.160. Splitting on the review session gives 6 students who skipped it with 2 passes (impurity 0.444) and 4 who attended it, all of whom passed, for a score of 0.267. The lowest score is 0.160, so the first question is “did you study 5.5 hours or less?”. We checked all the other thresholds in the script and none of them scores lower.
The right branch is already pure, so it becomes a leaf that predicts pass. The left branch has 5 students with 1 pass, an impurity of 0.32, so the tree asks again. Splitting that group at hours ≤ 3.5 scores 0.200, but splitting on the review session scores 0: the 4 students who skipped it all failed, and the 1 student who attended it passed. So the second question is “did you attend the review?”. The finished tree has two questions and three leaves, and it classifies all 10 students correctly.
The tree for the ten students, each box showing its question or its prediction.
3. Why a small change in the data can change the tree
The scikit-learn documentation lists instability among the disadvantages of decision trees: small variations in the data might result in a completely different tree being generated. It adds that practical algorithms are greedy, making the locally optimal choice at each node, so they cannot guarantee the globally optimal tree. You can see the first point in our example. Change one student: let the student who studied 5 hours and skipped the review pass instead of fail. Now the split at hours ≤ 3.5 separates 3 failures from 7 passes, scores 0, and the whole tree becomes one question. One changed label removed the second question and moved the first threshold from 5.5 to 3.5.
4. A common misconception: pure leaves mean a good tree
It is natural to read a tree that sorts every training example correctly as a tree that has learned the pattern. Our tree does that, and one of its leaves holds a single student. The documentation says decision-tree learners can create over-complex trees that do not generalize the data well, which it calls overfitting, and it names setting a minimum number of samples at a leaf, or a maximum depth, as ways to limit it. It suggests trying a minimum of 5 samples per leaf as a starting value. That tip is written for larger datasets, but applying it to our ten students shows the effect: with at least 5 students per leaf, only the split at hours ≤ 5.5 is allowed, and the tree stops after one question. The left leaf then reports a pass proportion of 0.2 for its 5 students, instead of being split further into a leaf of 4 and a leaf of 1.
The same documentation says the instability is mitigated by using decision trees within an ensemble, which means averaging or voting over many trees; this page does not cover how those are built.
5. Test yourself
Close this page and take a node that holds 8 students, 6 of whom passed and 2 of whom failed. Compute its Gini impurity, and say what the impurity would be if all 8 had passed. Reopen the page and compare. The answer is 2 × 0.75 × 0.25 = 0.375, and 0 for a node where all 8 passed. The first step where you slipped is the part to study again. For the general method, see how to test yourself.
What the sources found, and their limits
scikit-learn user guide, section 1.10 Decision Trees. Documentation for the scikit-learn library. It describes decision trees as a non-parametric supervised method for classification and regression that learns simple decision rules from the features, with a leaf for classification predicting the class proportions of the training examples that reached it. It gives the Gini and entropy impurity formulas, the weighted-impurity score for a candidate split, the greedy exhaustive search over features and midpoint thresholds, and the disadvantages of overfitting, instability across small changes in the data, piecewise constant predictions that do not extrapolate, and the lack of a guarantee of a globally optimal tree. Source: scikit-learn.org, decision trees, read on 2026-11-23.
Limits: the source is software documentation, not a textbook, so we read it for what trees do and not for proofs. We did not read its sections on pruning, missing values or regression criteria beyond their headings. The ten students, the three scores, the second question, the one-label change and the minimum-leaf example are our own arithmetic in the script and are not from the documentation. The data are made up.
How Professor Turing helps
Professor Turing is a tutor for adults learning any subject, in college or on their own. It asks you questions instead of giving the final answer, does not grade a bare guess, and remembers what you got wrong. No account is needed to start.
Bring a topic you are studying, such as why a tree picks one question before another. Its first reply asks what you already know before it teaches anything. If you answer with a bare guess, such as a term, it asks how you got there instead of saying right or wrong, and when you stay stuck it changes its approach and makes the next step smaller instead of giving the final answer. Later in a session it can offer a short test without help, scored apart from the tutoring, so you can tell what you can do alone from what the tutor carried you through.
It does not read or mark a written answer, and it does not write your explanation for you, so the explanation has to be yours. You must be 18 or older, and conversations are deleted after 7 days.
FAQ
What is the difference between Gini impurity and entropy? Both measure how mixed a node is, and both are 0 for a node where every example has the same label. The scikit-learn documentation gives Gini as the sum of p times (1 minus p) over the classes and entropy as minus the sum of p times log p. In our example the starting node, with 6 passes among 10 students, has a Gini impurity of 0.48.
Can a decision tree predict a number instead of a category? Yes. The scikit-learn documentation describes decision trees for both classification and regression. A regression tree predicts a constant for each region, so its predictions are piecewise constant, and the documentation notes that this makes trees poor at extrapolating beyond the range of the training data.
Start with what you're working on
Tell the tutor which topic you are studying and let it ask you the questions.
Start learning No account needed
See also: all study guides