---
title: "Extracting rules from decision tree"
subject: "Data Mining"
chapter: 3
key: "semester_7/data_mining:rules-from-decision-tree"
source: https://www.bctengineer.com/q/semester_7/data_mining/rules-from-decision-tree
site: BCT Engineering
---

# Extracting rules from decision tree

Data Mining · Chapter 3: Classification

- Asked in: year not given
- Video: [How to convert decision trees to rules](https://www.youtube.com/watch?v=PNF2eUiZAn0) — Chris Kimmer
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/data_mining/rules-from-decision-tree
- Whole chapter: https://www.bctengineer.com/md/semester_7/data_mining/chapter-3

## Question

How can rules be extracted from decision tree? Explain with an example.

## Short answer

For each path from root to leaf, create a rule with all attribute-value tests along the path combined with AND, and the leaf class as the consequent. For instance: IF age=youth AND student=no THEN buys_computer=no. The resulting rules are mutually exclusive and exhaustive, with as many rules as leaves.

## Answer

A decision tree can be converted into a set of IF-THEN rules, which are easier to read than a large tree.

#### Method
1. Create **one rule for each path** from the root to a leaf.
2. Each **attribute-value test** along the path is a condition; the tests are combined with **AND**.
3. The **leaf class label** is the rule's consequent (THEN part).
4. (Optional) Simplify the rules: remove a condition if this does not reduce rule accuracy (pessimistic estimate), and remove duplicate or redundant rules.

The rules from an unpruned tree are **mutually exclusive** (a record satisfies only one rule) and **exhaustive** (every record is covered). The number of rules equals the number of leaves.

#### Example (buys-computer tree)
```text
            age?
      young/ middle \senior
     student?  YES   credit_rating?
     no/  \yes       fair/    \excellent
     NO   YES        YES       NO
```
Rules:
1. IF age = young AND student = no THEN buys_computer = no
2. IF age = young AND student = yes THEN buys_computer = yes
3. IF age = middle THEN buys_computer = yes
4. IF age = senior AND credit_rating = fair THEN buys_computer = yes
5. IF age = senior AND credit_rating = excellent THEN buys_computer = no

Rule 3 has only one condition because its leaf is reached by a single test. The rule set is equivalent to the tree.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How many IF-THEN rules are extracted from an unpruned decision tree?
   A. One rule for each root-to-leaf path (number of leaves)
   B. One rule for each internal node
   C. One rule for each attribute
   D. One rule for each class value only
   Answer: A. Each path from root to a leaf gives one rule, so rules = leaves. (Key point: One rule per path)

2. How are the attribute tests along a path combined in the rule's IF part?
   A. With OR
   B. With XOR
   C. With AND
   D. Only the last test is kept
   Answer: C. Every test on the path must hold, so they are ANDed. (Key point: Combining tests)

3. What forms the THEN part of an extracted rule?
   A. The root attribute
   B. The class label at the leaf
   C. The attribute with highest gain
   D. The number of records in the node
   Answer: B. The leaf class label is the consequent. (Key point: Rule consequent)

4. In the buys-computer tree, what rule comes from age = middle_aged?
   A. IF age = middle_aged AND student = yes THEN buys_computer = yes
   B. IF age = middle_aged THEN buys_computer = no
   C. IF age = senior THEN buys_computer = yes
   D. IF age = middle_aged THEN buys_computer = yes
   Answer: D. The middle_aged branch is a pure leaf reached by one test, giving a short rule. (Key point: Example rule 3)

## Related in Data Mining

- [Overfitting in ID3 and decision tree rules](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Aid3-overfitting-rules) — Data Mining, chapter 3
- [Short note: Decision tree](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Adecision-tree-note) — Data Mining, chapter 3
- [Decision tree classifier and Hunt's algorithm](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Adecision-tree-hunt) — Data Mining, chapter 3
- [Decision tree advantages and disadvantages](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Adecision-tree-pros-cons) — Data Mining, chapter 3

## Related in other subjects

- [Explain decision tree analysis](https://www.bctengineer.com/question.md?key=semester_6%2Fengineering_economics%3Aexplain-decision-tree) — Engineering Economics, chapter 6, asked 5×
- [Decision tree for plant improvement alternatives](https://www.bctengineer.com/question.md?key=semester_6%2Fengineering_economics%3Adecision-tree-plant-alternatives) — Engineering Economics, chapter 6, asked 2×
- [Decision tree; infinite source blocking formulas](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Adecision-tree-infinite-sources) — Telecommunications, chapter 6, asked 2×
- [Decision tree; finite source blocking formulas](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Adecision-tree-finite-sources) — Telecommunications, chapter 6, asked 2×
