Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Decision Tree
2.1.
Advantages of decision trees
3.
Decision Tables
3.1.
Example of Decision Table
3.2.
Conversion of decision table into decision tree 
3.3.
Advantages of a Decision tree over Decision table
4.
FAQs
5.
Key Takeaways
Last Updated: Mar 27, 2024

Decision Tree and Decision Table

Author Aryan Raj
0 upvote

Introduction

Data is one of the foremost resources of an organization. Every organization wishes to preserve and fully utilize its data for decision-making. Once data is acquired, it must be organized in an application's database for later use. 

A database is a collection of facts, rules, and meta-data. There are different ways to organize a database. A variety of knowledge representations techniques, such as semantic nets, frames scripts, lists, decision trees, decision tables, etc., have been proposed for use over the years. One data representation scheme may be more efficient than others depending on the nature and type of problem. Thus, there is a need to map data from one representation to another. 

This mapping may give a faster response and reduce computation amount. Data in the form of rules is easy to understand and fast to extract and implement. Rules can be constructed from the data in a decision tree and decision table. 

The blog's primary focus is to construct rules from the data presented in the form of a decision tree and decision table. A human user can understand and modify a set of rules much more easily than he or she can understand and modify a decision tree or decision table. 

During Structured Analysis, various techniques and tools are used for system development. These are:

  • Data Dictionary
  • Data Flow Diagrams
  • Decision Tables
  • Structured English
  • Decision Trees
  • Pseudocode

Decision Tree

A Decision Tree is a graph that uses a branching method to display all the possible outcomes of any decision. It helps in processing logic involved in decision-making, and corresponding actions are taken. It is a diagram that shows conditions and their alternative actions within a horizontal tree framework. It helps the analyst consider the sequence of decisions and identifies the accurate decision that must be made.

Links are used for decisions, while Nodes represent goals. Decision trees simplify the knowledge acquisition process and are more natural than frames and rule knowledge representation techniques. 

Let’s understand this with an example:

Conditions included the sale amount (under $50) and whether the customer paid by cheque or credit card. The four steps possible were to:

  • Complete the sale after verifying the signature.
  • Complete the sale with no signature needed.
  • Communicate electronically with the bank for credit card authorization.
  • Call the supervisor for approval.

 

The below figure illustrates how this example can be drawn as a decision tree. In drawing the tree.

 

Advantages of decision trees

  • Decision trees represent the logic of If-Else in a pictorial form. 
  • Decision trees help the analyst to identify the actual decision to be made. 
  • Decision trees are useful for expressing the logic when the value is variable or action depending on a nested decision. 
  • It is used to verify the problems that involve a limited number of actions. 
     

Also see,  V Model in Software Engineering

Decision Tables

Data is stored in the tabular form inside decision tables using rows and columns. A decision table contains condition entries, condition stubs, action entries, and action stubs. The upper left quadrant contains conditions. The upper right quadrant contains condition alternatives or rules. The lower right quadrant contains action rules, and the lower-left quadrant contains actions to be taken. Verification and validation of the decision table are much easy to check, such as Inconsistencies, Contradictions, Incompleteness, and Redundancy.

Example of Decision Table

Let's consider the decision table given in table 1. 

In the table, there are multiple rules for a single Decision. The rules from a decision table can be made by just putting AND between conditions. 

The major rules which can be extracted (taken out) from the table are:

  • R1 = If (working-day = Y) ^ (holiday = N) ^ (Rainy-day = Y) Then, Go to office. 
  • R2 = If (working-day = N) ^ (holiday = N) ^ (Rainy-day = N) Then, Go to office.
  • R3 = If (working-day = N) ^ (holiday = Y) ^ (Rainy-day = Y) Then, Watch TV. 
  • R4 = If (working-day = N) ^ (holiday = Y) ^ (Rainy-day = N) Then, Go to picnic.

The above rules can be optimized by: 

Optimized R1= If (working-day = Y) then Go to office 

Or

Optimized R1= If (holiday = N) then Go to office 

Optimized R3= If (working-day = N) ^ (Rainy-day = Y) Then Watch TV

Or

Optimized R3= If (holiday = Y) ^ (Rainy-day = Y) Then Watch TV

Optimized R4= If (working-day = N) ^ (Rainy-day = N) 

Then go to the picnic.

Or

Optimized R4= If (holiday = Y) ^ (Rainy-day = N)

Then go to the picnic.

The tree given below is the resultant tree of Table 1.

The following rules are constructed from the decision tree as shown below.

R1= If (Day = Working) ^ (Outlook = Rainy)

Then Go To Office

 

R2= If (Day = Working) ^ (Outlook = Sunny)

Then Go To Office

 

R3= If (Day = Holiday) ^ (Outlook = Rainy)

Then Watch TV 

 

R4=If (Day = Holiday) ^ (Outlook = Sunny) 

Then Go To Picnic

In R1 and R2, there is no need to check the condition Outlook = Rainy and Outlook = Sunny if day = working because if the day is working, whether it is a sunny or rainy day, the decision is to Go to the office. The following rules are the optimized version of R1 and R2 above rules. 

R1 optimized: If (Day = Working) Then Go To Office 

R2 optimized: If (Day = Working) Then Go To Office 

The refinement/optimization step result is effective, efficient, and accurate rules.

Conversion of decision table into decision tree 

Data can be transformed from a decision table into a tree structure. The decision table can be converted into a decision tree by using the conversion method discussed or some other technique. The resultant tree has two categories: balanced trees and unbalanced trees. The figure shows the input and output of the conversion process.

 

Advantages of a Decision tree over Decision table

  • The decision tree takes advantage of the sequential structure of decision tree branches to notice the order of checking conditions and executing actions immediately.
  • Decision tree is used to verify the problems that involve a limited number of actions. 
  • All those actions and conditions that are critical are connected directly to other conditions and actions, whereas the conditions that do not matter are absent. In other words, the trees do not have to be symmetrical. 
  • Decision tree is helpful to express the logic when the value is variable, or action is dependent on the nested decision. 

FAQs

  1. What is the maximum depth in a decision tree?
    Maximum depth in a decision tree can be described as the length of the longest path from the root to the leaf node. The Max Depth value cannot exceed 30 on a 32-bit machine. The default value is 30 (Thirty). The root node is considered to have a depth of 0 (Zero). 
     
  2. How do you call a decision table from a decision tree?
    To call a decision table from a decision table, we can use DecisionTable.ObtainValue function.
    Example: @(Pega-RULES:DecisionTable).ObtainValue(tools,Primary,"pyBackgroundColorsForSubFeatures",false)
     
  3. What is the difference between a decision tree and a random forest?
    Decision Tree: A decision tree combines some decisions. At the same time, a decision tree is fast and operates efficiently on large data sets, especially the linear one. 
    Random Forest: A random forest combines of several decision trees; thus, it is a long process, yet slow. The random forest model needs rigorous training.
     
  4. What are the types of decision trees?
    The Decision trees can be divided into two types:
    i) Categorical variable decision tree
    ii) Continuous variable decision tree
     

Key Takeaways

In this article we have extensively discussed Decision tree and Decision table topics and their implementation along with with Example of decision tree with conversion.

Recommended Readings:

 

We hope that this blog has helped you enhance your knowledge regarding Decision tree and Decision table and if you would like to learn more, check out our articles on link. Do upvote our blog to help other ninjas grow. 

Also check out - Data Dictionary In Software Engineering

Happy Coding!

Live masterclass