Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconArtificial Intelligencebreadcumb forward arrow iconHow to Create Perfect Decision Tree | Decision Tree Algorithm [With Examples]

How to Create Perfect Decision Tree | Decision Tree Algorithm [With Examples]

Last updated:
30th Mar, 2020
Views
Read Time
5 Mins
share image icon
In this article
Chevron in toc
View All
How to Create Perfect Decision Tree | Decision Tree Algorithm [With Examples]

If you were wondering ‘how to create a decision tree’ or ‘can I create a decision tree in Java,’ you’ve come to the right place. In this article, we’ll find answers to such questions as we’ll be discussing decision trees in detail. You’ll find out what they are, why they are so popular, and how you can create one of them. 

Before you create a decision tree, you must be familiar with several other topics such as Linear Regression and algorithms. 

Top Machine Learning and AI Courses Online

What is a Decision Tree?

A decision tree gives you a map of all the possible outcomes of particular selections. It can help you plan out the future actions under different scenarios according to different choices. You can compare those possible outcomes on the basis of their probabilities and costs.

Ads of upGrad blog

As the name suggests, a decision tree shows a graph resembling a tree. It is a model of decisions, along with the outcomes and consequences of every one of them. Its ultimate goal is to help you perform classification correctly while going through the lowest number of choices possible. 

Trending Machine Learning Skills

Enrol for the Machine Learning Course from the World’s top Universities. Earn Masters, Executive PGP, or Advanced Certificate Programs to fast-track your career.

You can represent boolean functions by using decision trees as well. Each leaf node of a decision tree is a class label, and the internal nodes of the tree show the attributes. They begin with one node and then branch off into all the possibilities. Every one of those branches leads to more nodes that represent other possible consequences. You can create a decision tree in Java.  

A decision tree has various kinds of nodes:

  • Decision Nodes
  • Chance Nodes
  • End Nodes

The end nodes reflect the final result of a decision path while the chance nodes show the chances of particular outcomes. The decision nodes indicate the decision you’ll make that would lead to the possible results. You can use decision trees to map out algorithmic predictions as well as to make informal decisions. 

Now that you’re familiar with what a decision tree is, we should focus on digging a little deeper and understand why it’s prevalent. Let’s dive in. 

Applications of Decision Tree

Here are some applications of decision trees so you can see how prevalent they are:

  • Banks use them to classify their loan applications
  • Finance professionals use decision trees for option pricing
  • Categorizing exam papers according to the level of expertise of the candidates
  • Choosing whether to accept or reject a job offer
  • Making essential business decisions such as whether a company should modify its product or not.

You must’ve used decision trees yourself in making various choices in your life. Just come up with a few scenarios where you had to make an intricate decision. 

Advantages of Decision Tree

There are many advantages to using a decision tree. Here are they:

  • Decision trees produce rules that you can understand easily. You wouldn’t have difficulty conveying those rules to other systems.
  • They can handle both categorical as well as continuous variables
  • A decision tree will give you a simple indication of the importance of every field. You can easily make predictions (or classifications) according to the same.
  • Decision trees also perform feature selection implicitly that helps you with data exploration. 

Learn more: Artificial Intelligence Algorithms

Disadvantages of Decision Tree

Everything has its flaws, and decision trees are no exception. Here are some problems with using them:

  • Decision trees aren’t useful for performing estimation tasks. That’s because such jobs require the prediction of a continuous attribute’s value, and decision trees aren’t good at that.
  • Computationally, decision trees are more expensive than other options. It’ll cost you a lot to train a decision tree model as well in comparison to others. The pruning algorithms you’d use in making decision trees are also quite expensive as they require to build many sub-trees. 
  • If you have a high number of classes examples but a low number of training examples, your decision trees wouldn’t be much accurate, and their chances of containing errors would be significantly high. 

How to Create a Decision Tree

Let’s create a decision tree on whether a person would buy a computer or not. In this case, we’d have two classes, ‘Yes’ and ‘No.’ The first class refers to the people who would buy a computer, while the second refers to those who wouldn’t. First, we’ll calculate Information Gain and Entropy for these classes. 

Once we’ve calculated the Entropy of these classes, we’ll focus on information gain. We can classify the values of Entropy like this:

If Entropy is 0, it means the data is pure (homogenous)

If Entropy is 1, it means the data is impure (half-divided)

Let’s suppose our Entropy is impure. Then we’ll split the information gain on age. This way, our data will show how many people of a specific age bracket will buy this product and how many won’t. We can calculate the information gain for multiple attributes. But in our example, we found that the information gain is highest for ‘Age’ and the lowest for ‘Income.’ So, we’ll go with that. 

Here are the classification rules for this decision tree:

If someone’s age is less than 30 and if that person isn’t a student, they won’t buy the product so:

Age (<30) ^ student(no) = NO

But if someone whose age is less than 30 and is a student, they would buy the product:

Age (<30)^ student(yes) = YES

Know more about: Top 9 Machine Learning Libraries You Should Know About

Now, if their age lies between 31 and 40, they would surely buy the product:

Age(31…40) = YES

A person with age higher than 40 and a high credit rating wouldn’t buy:

Age(>40)^ credit_rating(high) = NO

On the other hand, if a person who is older than 40 but has an average credit rating, he or she would buy the product:

Age(>40)^ credit_rating(normal) = YES

By following these steps, you’d be able to create the perfect decision tree without any difficulty

Ads of upGrad blog

Popular AI and ML Blogs & Free Courses

Conclusion

Now you must know how to create a decision tree. You can learn a whole lot more about decision trees and the relevant algorithms in our machine learning course. We’re sure you’d get to enhance your knowledge there as you’ll get to learn how you can create a decision tree in Java, how you can use them in real-life, and more. 

If you’re interested to learn more about machine learning, check out IIIT-B & upGrad’s PG Diploma in Machine Learning & AI which is designed for working professionals and offers 450+ hours of rigorous training, 30+ case studies & assignments, IIIT-B Alumni status, 5+ practical hands-on capstone projects & job assistance with top firms.

Profile

Kechit Goyal

Blog Author
Experienced Developer, Team Player and a Leader with a demonstrated history of working in startups. Strong engineering professional with a Bachelor of Technology (BTech) focused in Computer Science from Indian Institute of Technology, Delhi.
Get Free Consultation

Selectcaret down icon
Select Area of interestcaret down icon
Select Work Experiencecaret down icon
By clicking 'Submit' you Agree to  
UpGrad's Terms & Conditions

Our Popular Machine Learning Course

Explore Free Courses

Suggested Blogs

15 Interesting MATLAB Project Ideas &#038; Topics For Beginners [2024]
82457
Diving into the world of engineering and data science, I’ve discovered the potential of MATLAB as an indispensable tool. It has accelerated my c
Read More

by Pavan Vadapalli

09 Jul 2024

5 Types of Research Design: Elements and Characteristics
47126
The reliability and quality of your research depend upon several factors such as determination of target audience, the survey of a sample population,
Read More

by Pavan Vadapalli

07 Jul 2024

Biological Neural Network: Importance, Components &#038; Comparison
50612
Humans have made several attempts to mimic the biological systems, and one of them is artificial neural networks inspired by the biological neural net
Read More

by Pavan Vadapalli

04 Jul 2024

Production System in Artificial Intelligence and its Characteristics
86790
The AI market has witnessed rapid growth on the international level, and it is predicted to show a CAGR of 37.3% from 2023 to 2030. The production sys
Read More

by Pavan Vadapalli

03 Jul 2024

AI vs Human Intelligence: Difference Between AI &#038; Human Intelligence
112983
In this article, you will learn about AI vs Human Intelligence, Difference Between AI & Human Intelligence. Definition of AI & Human Intelli
Read More

by Pavan Vadapalli

01 Jul 2024

Career Opportunities in Artificial Intelligence: List of Various Job Roles
89547
Artificial Intelligence or AI career opportunities have escalated recently due to its surging demands in industries. The hype that AI will create tons
Read More

by Pavan Vadapalli

26 Jun 2024

Gini Index for Decision Trees: Mechanism, Perfect &#038; Imperfect Split With Examples
70805
As you start learning about supervised learning, it’s important to get acquainted with the concept of decision trees. Decision trees are akin to
Read More

by MK Gurucharan

24 Jun 2024

Random Forest Vs Decision Tree: Difference Between Random Forest and Decision Tree
51730
Recent advancements have paved the growth of multiple algorithms. These new and blazing algorithms have set the data on fire. They help in handling da
Read More

by Pavan Vadapalli

24 Jun 2024

Basic CNN Architecture: Explaining 5 Layers of Convolutional Neural Network
270717
Introduction In the last few years of the IT industry, there has been a huge demand for once particular skill set known as Deep Learning. Deep Learni
Read More

by MK Gurucharan

21 Jun 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon