How a decision tree sorts data

A decision tree classifies an item by asking a sequence of questions about its features. For an email, a question might be whether it contains a suspicious link; for a plant, whether its leaves are needle-shaped. Each answer selects a branch, leading to another question or, eventually, a category such as “spam” or “conifer.”

The tree’s structure makes the decision path visible: instead of producing a label with no explanation, it can show which questions led to that result. A tree can also estimate a number rather than choose a category—for instance, predicting a delivery time—by assigning a value at the end of a path.

How the branches are chosen

A learning algorithm builds the tree from examples that already have known answers. At each step, it searches for a feature-based question that separates those examples into more useful groups. If a question divides a mixed pile of labeled cases into groups that are mostly one category or another, it is a good candidate for a branch.

The process repeats within each group. A tree might first separate messages with links from those without them, then ask a different question about the messages that remain. This is how simple questions combine into a more complicated rule without anyone having to write every possible path by hand.

Why a tree can go wrong

More branches can let a model fit its training examples closely, but that may also make it memorize quirks that do not recur in new data. A tree that relies on an accidental pattern in its examples can make poor decisions when conditions change. Limiting its depth—the number of questions along a path—or requiring more examples before it creates a branch can make it simpler and more reliable.

That tradeoff is part of the appeal: a decision tree is easy to follow, but its usefulness depends on asking the right questions and keeping the path from becoming an overfitted maze.