Abstract background

Decision tree: how it works, what it solves and where it stops

A decision tree divides a data set step by step on the basis of mutually exclusive characteristics, until groups remain about which you can make a prediction. It is one of the most powerful and most explainable tools in the data scientist’s toolbox, provided you prune it sensibly.

Key takeaways

  • A decision tree is a technique that divides a set on the basis of mutually exclusive characteristics, in a series of successive choices.
  • The algorithm chooses at each step the split that reduces disorder (entropy) the most; that reduction is called information gain.
  • Choose characteristics on objective grounds dictated by the data, not on the subjective preference of the analyst.
  • Do not make statements about what does not occur in the training set, and distinguish coincidental from causal relationships.
  • A tree that is worked out in too much detail has end points with too few cases. Prune, but with moderation: over-pruning leaves a trivial tree.

What is a decision tree?

A decision tree is a model that splits a data set into ever smaller subsets through successive choices on mutually exclusive characteristics, so that new cases can be classified and predicted along the same branches.

Decision trees are one of the six widely used methods of predictive analytics. At first sight the technique looks like a visual way of classifying data rather than a method for investigating information. Yet the tree that arises after analysing (part of) the information can be used very well to make predictions.

Introduction: the restaurant example

Eating in a restaurant with an extensive menu quickly becomes a collection of difficult choices. Do you want a starter besides the main course, and a dessert later? Not every combination of starter and main course tastes equally good, not every wine goes with every dish, and a choice once made continues to have an effect until the end of the evening. As a guest you could draw a decision tree to map all the choices.

The restaurant owner has his own headaches: does his purchasing correspond to the orders of that evening? To what extent can he estimate and predict the choices of each guest? Both guest and owner face a series of choices in which one option excludes the others, a situation that occurs very often. With data the situation is reversed: you do not use the tree to depict information, but to take decisions.

Which type of problem does a decision tree solve?

A decision tree makes a division on the basis of mutually exclusive characteristics. With passenger cars, colour is such a characteristic: a blue car is not red. The choice can be set up in two ways:

  • Single choice: only blue versus not blue.
  • Multiple choice: blue, red, silver, black, white and other.

The number of wheels, on the other hand, is a clear characteristic but unsuitable for distinguishing cars: almost all passenger cars, many vans and some lorries have four. A characteristic that does not discriminate loses its value.

Is the count accurate enough?

Rare values are a problem. It is nice to include a colour like “British racing green”, but probably only very few cars have it. The question then is to what extent a limited set of data can predict the behaviour of a large set: given the size of the test set, which accuracy is achievable and justifiable?

Make no statement about what does not occur

Five cars are in a car park: red, blue, white, black and yellow. On this basis each colour has a probability of 0.20. It seems as if green, brown and purple cars do not exist. But you cannot say anything about that: it is unclear whether cars of another colour do not exist, or simply do not occur in the test set.

Coincidental or causal?

External characteristics are often used to track down less visible properties: red cars would get more speeding fines, white cars would be parked illegally more often. Precisely when tracking down such links it is essential to distinguish between a coincidental and a causal correspondence.

How a decision tree is built

By making successive choices, a set is divided into an ever larger number of subsets. At each decision moment the set is divided into two or more subsets, depending on the number of values of the chosen characteristic. With a split on property x1, a share p1 of the cases has the property and a share 1 − p1 does not. The resulting groups are divided again: the group with x1 is tested for property x2, the other group for x3. Sometimes only one branch is worked out further.

In the restaurant, after the choice “no starter” it is not logical to list all starters. The tree therefore gets longer and shorter branches, and some choices appear in several places.

Objective grounds

Which characteristics qualify for building the tree, and in which order? It is of the utmost importance to base the choice on objective grounds (dictated by the information) and not on subjective grounds (determined by the data analyst). Certainly with large volumes of data, automation is necessary.

Entropy and information gain

Central to the search for the right tree is the entropy H of the set: a measure of the disorder in it. If the whole set is captured in a clearly structured decision tree, then H = 0, because there is no disorder. For sets that have not yet been structured, entropy is high. An algorithm reduces the disorder step by step, each time it creates a new series of branches. The decrease in entropy per step is called the information gain (IG) of that step. At the end the algorithm has used all available characteristics and entropy has reached its lowest possible value for that data set.

As soon as the set is captured in a tree, new information can be classified immediately. The assumption is that the set used for building the tree is representative of all information.

The limitations of decision trees

Against the intuitive correctness and clarity of the decision tree there are a number of limitations. The most important one: the set must be structurable by a tree, meaning that each characteristic offers an opportunity to make a choice. Not every set allows this. In some sets, combinations of characteristics weigh far more heavily than the individual characteristics. In that case deriving rules, as in business rules, is a better and more reliable technique.

Prune the tree back to acceptable proportions

Another danger is working out the tree in too much detail. Each end point then contains too few elements and therefore too little weight. Most algorithms have a pruning option that cuts a built tree back to the minimal form required by the demanded accuracy. Apply it with moderation and great care: too often the pruning option leaves a tree with a trivial solution to the problem.

Decision tree versus neural network

Both predict, but they differ strongly in explainability.

Decision tree

Neural network

Explainable

Yes, every branch is readable

Hardly, a black box

Data needed

Modest

Large volumes

Complex patterns

Limited

Strong

Main risk

Too detailed, overfitting

Opaque decisions

Typical use

Credit, churn, triage

Images, speech, text

How Diamond Decisions applies decision trees

Diamond Decisions often chooses a decision tree as the first model, because the people who decide can read it. After inspiration on what prediction can deliver, business modeling defines the decision and the characteristics that may be used, data analytics builds, tests and prunes the tree, and the decision makers check whether the branches make sense in practice.

Talk to the author

Herman van DellenHerman van Dellen
Diamond Decisions

Discuss your question with Herman

Tell us which decision needs to improve. In a no-obligation conversation we show you where your data delivers the most.

Schedule an introduction →

Step 3 of our approach

Diamond Data Analytics

A data warehouse that starts with your most important decisions and is ready for conversational AI: a working prototype within 24 hours.

Explore Data Analytics →

Frequently asked questions

01

What is a decision tree?

A model that splits a data set step by step on mutually exclusive characteristics, so that new cases can be classified and predicted along the branches.

02

What are entropy and information gain?

Entropy is a measure of the disorder in a set. Information gain is the decrease in entropy achieved by a split. The algorithm chooses the split with the highest information gain each time.

03

Why do you have to prune a decision tree?

A tree that is too detailed has end points with too few cases, so its predictions carry little weight. Pruning cuts the tree back to the form that the required accuracy allows, but over-pruning leaves a trivial tree.

04

What is the difference between a decision tree and business rules?

A decision tree splits on one characteristic at a time. Business rules can capture combinations of characteristics in one if-then rule, which works better when combinations weigh more heavily than individual characteristics.

05

Are decision trees suitable for SMEs?

Yes. They need relatively little data, can be built with common tools and can be explained to employees and customers, which makes them a good first predictive model.

Further reading

About the author

Herman van Dellen

Herman van Dellen

Herman is a very experienced data scientist who has applied machine learning and statistics for many years in areas such as CRM, BI and data warehousing. He built his career at IBM, where he founded the Business Intelligence Services Unit.

About Diamond Decisions

Diamond Decisions helps organizations become better by enabling better decisions. We don’t start with data, dashboards or AI, but with the decision that needs to improve, and work back from there to KPIs, data and technology. We do that in four steps: inspiration and alignment, business modeling, analytics and data platform and data-driven decision makers. That way BI and AI don’t remain an IT project, but deliver value every day.

Schrijf je in voor de Masterclass