SlideShare a Scribd company logo
Decision Tree In R | Decision Tree Algorithm | Data Science Tutorial | Machine Learning |Simplilearn
What’s in it for you?
What is a Decision Tree?
What problems can be solved using Decision Trees?
How does a Decision Tree work?
Use Case: Survival prediction in R
What is a Decision Tree?
Left or right?
What is a Decision Tree?
Wait or go? Left or right?
What is a Decision Tree?
Decision Tree is a tree shaped algorithm used to determine a course of action.
Each branch of the tree represents a possible decision, occurrence or reaction
Wait or go? Left or right?
What is a Decision Tree?
What is a Decision Tree?
Shopkeeper
What is a Decision Tree?
I must organize
my stall..
Shopkeeper
What is a Decision Tree?
Shopkeeper
What is a Decision Tree?
Is it coloured orange?
Is it round?
No Yes
YesNo
Shopkeeper
What problems can be solved using Decision Tree?
Classification:
Identifying to which set an object belongs
Example: Carrot is orange while broccoli is
green
What problems can be solved using Decision Tree?
Classification:
Identifying to which set an object belongs
Example: Carrot is orange while broccoli is
green
Regression:
Regression problems have continuous or
numerical valued output variables
Example: Predicting the profits of a company
How does a Decision Tree work?
Terms you must know
first…..
How does a Decision Tree work?
NODES
Each internal node in a decision tree is a test which splits the objects into
different categories
Is it coloured orange?
Is it round?
No Yes
YesNo
Terms you must know
first…..
How does a Decision Tree work?
Is it coloured orange?
Is it round?
No Yes
YesNoThis is a node
Terms you must know
first…..
NODES
Each internal node in a decision tree is a test which splits the objects into
different categories
How does a Decision Tree work?
Is it coloured orange?
Is it round?
No Yes
YesNo
ROOT NODE
The node at the top of the decision tree is called the Root node
Terms you must know
first…..
How does a Decision Tree work?
ROOT NODE
The node at the top of the decision tree is called the Root node
Is it coloured orange?
Is it round?
No Yes
YesNo
This is a root node
Terms you must know
first…..
How does a Decision Tree work?
LEAF NODE
Each external node in a decision tree is called the leaf node. The leaf
node is the output
Is it coloured orange?
Is it round?
No Yes
YesNo
Terms you must know
first…..
How does a Decision Tree work?
Is it coloured orange?
Is it round?
No Yes
YesNo
This is a leaf node
LEAF NODE
Each external node in a decision tree is called the leaf node. The leaf
node is the output
Terms you must know
first…..
How does a Decision Tree work?
ENTROPY
Entropy is a measure of the messiness of your data collection. The
messier or more random your data, higher will be the entropy
Terms you must know
first…..
How does a Decision Tree work?
This collection has high entropy
Terms you must know
first…..
ENTROPY
Entropy is a measure of the messiness of your data collection. The
messier or more random your data, higher will be the entropy
How does a Decision Tree work?
This collection has high entropy
This collection has low entropy
Terms you must know
first…..
ENTROPY
Entropy is a measure of the messiness of your data collection. The
messier or more random your data, higher will be the entropy
How does a Decision Tree work?
INFORMATION GAIN
Information gain is the decrease obtained in entropy by splitting the data
set based on some condition
Is it coloured orange?
Is it round?
No Yes
YesNo
E1
E2
Terms you must know
first…..
How does a Decision Tree work?
INFORMATION GAIN
Information gain is the decrease obtained in entropy by splitting the data
set based on some condition
Is it coloured orange?
Is it round?
No Yes
YesNo
E1
E2
E1>E2
INFORMATION GAIN=E1-E2
Terms you must know
first…..
How does a Decision Tree work?
Hi, my cupboard is
a mess. I must
organize my stuff..
How does a Decision Tree work?
Classify the objects based
on their attribute set using
decision trees
How does a Decision Tree work?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Let’s look at the attributes
for each object
How does a Decision Tree work?
• We split at each level based on certain
conditions on the attributes
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
How does a Decision Tree work?
• We split at each level based on certain
conditions on the attributes
• Splitting aims at reducing the entropy
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
How does a Decision Tree work?
• We split at each level based on certain
conditions on the attributes
• Splitting aims at reducing the entropy
-∑ⁱₓ₌₁p(valueₓ).log₂(p(valueₓ))
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
How does a Decision Tree work?
-[2/9.log₂(2/9) + 2/9.log₂(2/9) + 1/9.log₂(1/9) + 4/9.log₂(4/9)]=
-∑ⁱₓ₌₁p(valueₓ).log₂(p(valueₓ))
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
How does a Decision Tree work?
-[2/9.log₂(2/9) + 2/9.log₂(2/9) + 1/9.log₂(1/9) + 4/9.log₂(4/9)]= 1.8282
-∑ⁱₓ₌₁p(valueₓ).log₂(p(valueₓ))
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
How does a Decision Tree work?
Now we must find the conditions
for our split. Every split must give
us the maximum achievable
information gain Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
How does a Decision Tree work?
Our first split will be on
shape as that will
directly segregate the
balls
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
E1 = 1.8282
How does a Decision Tree work?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
E2 = 1.3784
E1 = 1.8282
How does a Decision Tree work?
Our second split will be
on size as that will
directly segregate the
books
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
E2 = 1.3784
E1 = 1.8282
How does a Decision Tree work?
Shape == Rectangle?
Size>5?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
E3 = 0.716
E2 = 1.3784
E1 = 1.8282
How does a Decision Tree work?
Our third split will
once again be on
size
Size>5?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
E3 = 0.716
E2 = 1.3784
E1 = 1.8282
How does a Decision Tree work?
Size>3?
Size>5?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
E3 = 0.716
E2 = 1.3784
E1 = 1.8282
E4 = 0
How does a Decision Tree work?
Size>3?
Size>5?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
E2 = 1.3784
E3 = 0.716
E1 = 1.8282
E4 = 0
How does a Decision Tree work?
All our objects are now
classified with 100%
accuracy
Size>3?
Size>5?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
How does a Decision Tree work?
All our objects are now
classified with 100%
accuracy
Size>3?
Size>5?
Shape Size Label Number
round 10 ball 2
rectangle 6 book 2
rectangle 4 card 1
rectangle 2 blocks 4
total 9
Shape == Rectangle?
Use Case: Survival prediction in R
Let’s implement classification of a data set based on
Information Gain
Let’s implement classification of a data set based on
Information Gain
This is the ID3 algorithm
Use Case: Survival prediction in R
Let’s implement classification of a data set based on
Information Gain
This is the ID3 algorithm
We will be using the RStudio IDE
Use Case: Survival prediction in R
• A ship had 20 lifeboats
Use Case: Survival prediction in R
• A ship had 20 lifeboats
• The lifeboats were
distributed based on the
class, gender and age of
the passengers
Use Case: Survival prediction in R
• A ship had 20 lifeboats
• The lifeboats were
distributed based on the
class, gender and age of
the passengers
• We will develop a model
that recognises the
relationship between these
factors and predicts the
survival of a passenger
accordingly
Use Case: Survival prediction in R
Use Case: Survival prediction in R
We will be using a data set which
specifies if a passenger on a ship
survived it’s wreck or not
1 indicates the
person survived the
wreck
We will be using a data set which
specifies if a passenger on a ship
survived it’s wreck or not
Use Case: Survival prediction in R
The luxury class
of the cabin
Use Case: Survival prediction in R
We will be using a data set which
specifies if a passenger on a ship
survived it’s wreck or not
Numbers of siblings
on board
Use Case: Survival prediction in R
We will be using a data set which
specifies if a passenger on a ship
survived it’s wreck or not
Numbers of parents
on board
Use Case: Survival prediction in R
We will be using a data set which
specifies if a passenger on a ship
survived it’s wreck or not
Disembark location
Use Case: Survival prediction in R
We will be using a data set which
specifies if a passenger on a ship
survived it’s wreck or not
What is DecisionTree? Problems solved using DecisionTrees
How does a decision tree work?
Key Takeaways
Predicting survivors using R Determining accuracy of prediction
Terms to know
So what’s
your next step?

More Related Content

What's hot (20)

PPTX
Decision Tree Algorithm With Example | Decision Tree In Machine Learning | Da...
Simplilearn
 
PPTX
Machine Learning Tutorial | Machine Learning Basics | Machine Learning Algori...
Simplilearn
 
PPTX
Random forest
Musa Hawamdah
 
PPTX
Random forest
Ujjawal
 
PPTX
Random forest algorithm
Rashid Ansari
 
PPT
Decision tree and random forest
Lippo Group Digital
 
PPTX
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Simplilearn
 
PPTX
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Simplilearn
 
PPT
Decision tree
Ami_Surati
 
PPTX
Lect9 Decision tree
hktripathy
 
PPTX
Linear Regression Analysis | Linear Regression in Python | Machine Learning A...
Simplilearn
 
PPTX
Decision Tree Algorithm & Analysis | Machine Learning Algorithm | Data Scienc...
Edureka!
 
PDF
Decision trees in Machine Learning
Mohammad Junaid Khan
 
PDF
Data Science: Applying Random Forest
Edureka!
 
PDF
Machine Learning Algorithm - Decision Trees
Kush Kulshrestha
 
PPTX
Decision Tree Learning
Md. Ariful Hoque
 
PPTX
Predicting house prices_Regression
Sruti Jain
 
PPTX
Decision tree
ShraddhaPandey45
 
PPT
2.4 rule based classification
Krish_ver2
 
PDF
Cross-validation Tutorial: What, how and which?
Pradeep Redddy Raamana
 
Decision Tree Algorithm With Example | Decision Tree In Machine Learning | Da...
Simplilearn
 
Machine Learning Tutorial | Machine Learning Basics | Machine Learning Algori...
Simplilearn
 
Random forest
Musa Hawamdah
 
Random forest
Ujjawal
 
Random forest algorithm
Rashid Ansari
 
Decision tree and random forest
Lippo Group Digital
 
Random Forest Algorithm - Random Forest Explained | Random Forest In Machine ...
Simplilearn
 
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Simplilearn
 
Decision tree
Ami_Surati
 
Lect9 Decision tree
hktripathy
 
Linear Regression Analysis | Linear Regression in Python | Machine Learning A...
Simplilearn
 
Decision Tree Algorithm & Analysis | Machine Learning Algorithm | Data Scienc...
Edureka!
 
Decision trees in Machine Learning
Mohammad Junaid Khan
 
Data Science: Applying Random Forest
Edureka!
 
Machine Learning Algorithm - Decision Trees
Kush Kulshrestha
 
Decision Tree Learning
Md. Ariful Hoque
 
Predicting house prices_Regression
Sruti Jain
 
Decision tree
ShraddhaPandey45
 
2.4 rule based classification
Krish_ver2
 
Cross-validation Tutorial: What, how and which?
Pradeep Redddy Raamana
 

Similar to Decision Tree In R | Decision Tree Algorithm | Data Science Tutorial | Machine Learning |Simplilearn (20)

PDF
13 Machine Learning Supervised Decision Trees
Andres Mendez-Vazquez
 
PDF
Decision Tree-ID3,C4.5,CART,Regression Tree
Sharmila Chidaravalli
 
PDF
CSA 3702 machine learning module 2
Nandhini S
 
DOCX
Classification Using Decision Trees and RulesChapter 5.docx
monicafrancis71118
 
PDF
Data Science Machine LearningClassification.pdf
messagetome133
 
PPTX
Decision Tree ID3 Algorithm | Decision Tree | ID3 Algorithm | Machine Learnin...
Simplilearn
 
PPTX
Decision Trees
Student
 
PPTX
Data Science-entropy machine learning.pptx
ZainabShahzad9
 
PPTX
supervised machine learning algorithms support vector machine
pranalisonawane8600
 
PDF
7 decision tree
tafosepsdfasg
 
PPT
Machine Learning 3 - Decision Tree Learning
butest
 
PDF
Decision tree learning
Dr. Radhey Shyam
 
PPT
decisiontrees.ppt
PriyadharshiniG41
 
PPT
decisiontrees.ppt
LvlShivaNagendra
 
PPT
decisiontrees (3).ppt
LvlShivaNagendra
 
PDF
Understanding Decision Trees in Machine Learning: A Comprehensive Guide
CyberPro Magazine
 
PPTX
[Women in Data Science Meetup ATX] Decision Trees
Nikolaos Vergos
 
PPTX
Forms of learning in ai
Robert Antony
 
PPTX
Ai & Machine learning - 31140523010 - BDS302.pptx
BhaktMahadevKA
 
PPTX
Decision Tree Machine Learning Detailed Explanation.
DrezzingGaming
 
13 Machine Learning Supervised Decision Trees
Andres Mendez-Vazquez
 
Decision Tree-ID3,C4.5,CART,Regression Tree
Sharmila Chidaravalli
 
CSA 3702 machine learning module 2
Nandhini S
 
Classification Using Decision Trees and RulesChapter 5.docx
monicafrancis71118
 
Data Science Machine LearningClassification.pdf
messagetome133
 
Decision Tree ID3 Algorithm | Decision Tree | ID3 Algorithm | Machine Learnin...
Simplilearn
 
Decision Trees
Student
 
Data Science-entropy machine learning.pptx
ZainabShahzad9
 
supervised machine learning algorithms support vector machine
pranalisonawane8600
 
7 decision tree
tafosepsdfasg
 
Machine Learning 3 - Decision Tree Learning
butest
 
Decision tree learning
Dr. Radhey Shyam
 
decisiontrees.ppt
PriyadharshiniG41
 
decisiontrees.ppt
LvlShivaNagendra
 
decisiontrees (3).ppt
LvlShivaNagendra
 
Understanding Decision Trees in Machine Learning: A Comprehensive Guide
CyberPro Magazine
 
[Women in Data Science Meetup ATX] Decision Trees
Nikolaos Vergos
 
Forms of learning in ai
Robert Antony
 
Ai & Machine learning - 31140523010 - BDS302.pptx
BhaktMahadevKA
 
Decision Tree Machine Learning Detailed Explanation.
DrezzingGaming
 
Ad

More from Simplilearn (20)

PPTX
Top 50 Scrum Master Interview Questions | Scrum Master Interview Questions & ...
Simplilearn
 
PPTX
Bagging Vs Boosting In Machine Learning | Ensemble Learning In Machine Learni...
Simplilearn
 
PPTX
Future Of Social Media | Social Media Trends and Strategies 2025 | Instagram ...
Simplilearn
 
PPTX
SQL Query Optimization | SQL Query Optimization Techniques | SQL Basics | SQL...
Simplilearn
 
PPTX
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
Simplilearn
 
PPTX
How To Start Influencer Marketing Business | Influencer Marketing For Beginne...
Simplilearn
 
PPTX
Cyber Security Roadmap 2025 | How To Become Cyber Security Engineer In 2025 |...
Simplilearn
 
PPTX
How To Become An AI And ML Engineer In 2025 | AI Engineer Roadmap | AI ML Car...
Simplilearn
 
PPTX
What Is GitHub Copilot? | How To Use GitHub Copilot? | How does GitHub Copilo...
Simplilearn
 
PPTX
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
PPTX
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
PPTX
Top 7 High Paying AI Certifications Courses For 2025 | Best AI Certifications...
Simplilearn
 
PPTX
Data Cleaning In Data Mining | Step by Step Data Cleaning Process | Data Clea...
Simplilearn
 
PPTX
Top 10 Data Analyst Projects For 2025 | Data Analyst Projects | Data Analysis...
Simplilearn
 
PPTX
AI Engineer Roadmap 2025 | AI Engineer Roadmap For Beginners | AI Engineer Ca...
Simplilearn
 
PPTX
Machine Learning Roadmap 2025 | Machine Learning Engineer Roadmap For Beginne...
Simplilearn
 
PPTX
Kotter's 8-Step Change Model Explained | Kotter's Change Management Model | S...
Simplilearn
 
PPTX
Gen AI Engineer Roadmap For 2025 | How To Become Gen AI Engineer In 2025 | Si...
Simplilearn
 
PPTX
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
PPTX
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Top 50 Scrum Master Interview Questions | Scrum Master Interview Questions & ...
Simplilearn
 
Bagging Vs Boosting In Machine Learning | Ensemble Learning In Machine Learni...
Simplilearn
 
Future Of Social Media | Social Media Trends and Strategies 2025 | Instagram ...
Simplilearn
 
SQL Query Optimization | SQL Query Optimization Techniques | SQL Basics | SQL...
Simplilearn
 
SQL INterview Questions .pTop 45 SQL Interview Questions And Answers In 2025 ...
Simplilearn
 
How To Start Influencer Marketing Business | Influencer Marketing For Beginne...
Simplilearn
 
Cyber Security Roadmap 2025 | How To Become Cyber Security Engineer In 2025 |...
Simplilearn
 
How To Become An AI And ML Engineer In 2025 | AI Engineer Roadmap | AI ML Car...
Simplilearn
 
What Is GitHub Copilot? | How To Use GitHub Copilot? | How does GitHub Copilo...
Simplilearn
 
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Top 7 High Paying AI Certifications Courses For 2025 | Best AI Certifications...
Simplilearn
 
Data Cleaning In Data Mining | Step by Step Data Cleaning Process | Data Clea...
Simplilearn
 
Top 10 Data Analyst Projects For 2025 | Data Analyst Projects | Data Analysis...
Simplilearn
 
AI Engineer Roadmap 2025 | AI Engineer Roadmap For Beginners | AI Engineer Ca...
Simplilearn
 
Machine Learning Roadmap 2025 | Machine Learning Engineer Roadmap For Beginne...
Simplilearn
 
Kotter's 8-Step Change Model Explained | Kotter's Change Management Model | S...
Simplilearn
 
Gen AI Engineer Roadmap For 2025 | How To Become Gen AI Engineer In 2025 | Si...
Simplilearn
 
Top 10 Data Analyst Certification For 2025 | Best Data Analyst Certification ...
Simplilearn
 
Complete Data Science Roadmap For 2025 | Data Scientist Roadmap For Beginners...
Simplilearn
 
Ad

Recently uploaded (20)

PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Governor Josh Stein letter to NC delegation of U.S. House
Mebane Rash
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 

Decision Tree In R | Decision Tree Algorithm | Data Science Tutorial | Machine Learning |Simplilearn

  • 2. What’s in it for you? What is a Decision Tree? What problems can be solved using Decision Trees? How does a Decision Tree work? Use Case: Survival prediction in R
  • 3. What is a Decision Tree?
  • 4. Left or right? What is a Decision Tree?
  • 5. Wait or go? Left or right? What is a Decision Tree?
  • 6. Decision Tree is a tree shaped algorithm used to determine a course of action. Each branch of the tree represents a possible decision, occurrence or reaction Wait or go? Left or right? What is a Decision Tree?
  • 7. What is a Decision Tree? Shopkeeper
  • 8. What is a Decision Tree? I must organize my stall.. Shopkeeper
  • 9. What is a Decision Tree? Shopkeeper
  • 10. What is a Decision Tree? Is it coloured orange? Is it round? No Yes YesNo Shopkeeper
  • 11. What problems can be solved using Decision Tree? Classification: Identifying to which set an object belongs Example: Carrot is orange while broccoli is green
  • 12. What problems can be solved using Decision Tree? Classification: Identifying to which set an object belongs Example: Carrot is orange while broccoli is green Regression: Regression problems have continuous or numerical valued output variables Example: Predicting the profits of a company
  • 13. How does a Decision Tree work? Terms you must know first…..
  • 14. How does a Decision Tree work? NODES Each internal node in a decision tree is a test which splits the objects into different categories Is it coloured orange? Is it round? No Yes YesNo Terms you must know first…..
  • 15. How does a Decision Tree work? Is it coloured orange? Is it round? No Yes YesNoThis is a node Terms you must know first….. NODES Each internal node in a decision tree is a test which splits the objects into different categories
  • 16. How does a Decision Tree work? Is it coloured orange? Is it round? No Yes YesNo ROOT NODE The node at the top of the decision tree is called the Root node Terms you must know first…..
  • 17. How does a Decision Tree work? ROOT NODE The node at the top of the decision tree is called the Root node Is it coloured orange? Is it round? No Yes YesNo This is a root node Terms you must know first…..
  • 18. How does a Decision Tree work? LEAF NODE Each external node in a decision tree is called the leaf node. The leaf node is the output Is it coloured orange? Is it round? No Yes YesNo Terms you must know first…..
  • 19. How does a Decision Tree work? Is it coloured orange? Is it round? No Yes YesNo This is a leaf node LEAF NODE Each external node in a decision tree is called the leaf node. The leaf node is the output Terms you must know first…..
  • 20. How does a Decision Tree work? ENTROPY Entropy is a measure of the messiness of your data collection. The messier or more random your data, higher will be the entropy Terms you must know first…..
  • 21. How does a Decision Tree work? This collection has high entropy Terms you must know first….. ENTROPY Entropy is a measure of the messiness of your data collection. The messier or more random your data, higher will be the entropy
  • 22. How does a Decision Tree work? This collection has high entropy This collection has low entropy Terms you must know first….. ENTROPY Entropy is a measure of the messiness of your data collection. The messier or more random your data, higher will be the entropy
  • 23. How does a Decision Tree work? INFORMATION GAIN Information gain is the decrease obtained in entropy by splitting the data set based on some condition Is it coloured orange? Is it round? No Yes YesNo E1 E2 Terms you must know first…..
  • 24. How does a Decision Tree work? INFORMATION GAIN Information gain is the decrease obtained in entropy by splitting the data set based on some condition Is it coloured orange? Is it round? No Yes YesNo E1 E2 E1>E2 INFORMATION GAIN=E1-E2 Terms you must know first…..
  • 25. How does a Decision Tree work? Hi, my cupboard is a mess. I must organize my stuff..
  • 26. How does a Decision Tree work? Classify the objects based on their attribute set using decision trees
  • 27. How does a Decision Tree work? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Let’s look at the attributes for each object
  • 28. How does a Decision Tree work? • We split at each level based on certain conditions on the attributes Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9
  • 29. How does a Decision Tree work? • We split at each level based on certain conditions on the attributes • Splitting aims at reducing the entropy Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9
  • 30. How does a Decision Tree work? • We split at each level based on certain conditions on the attributes • Splitting aims at reducing the entropy -∑ⁱₓ₌₁p(valueₓ).log₂(p(valueₓ)) Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9
  • 31. How does a Decision Tree work? -[2/9.log₂(2/9) + 2/9.log₂(2/9) + 1/9.log₂(1/9) + 4/9.log₂(4/9)]= -∑ⁱₓ₌₁p(valueₓ).log₂(p(valueₓ)) Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9
  • 32. How does a Decision Tree work? -[2/9.log₂(2/9) + 2/9.log₂(2/9) + 1/9.log₂(1/9) + 4/9.log₂(4/9)]= 1.8282 -∑ⁱₓ₌₁p(valueₓ).log₂(p(valueₓ)) Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9
  • 33. How does a Decision Tree work? Now we must find the conditions for our split. Every split must give us the maximum achievable information gain Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9
  • 34. How does a Decision Tree work? Our first split will be on shape as that will directly segregate the balls Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 E1 = 1.8282
  • 35. How does a Decision Tree work? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle? E2 = 1.3784 E1 = 1.8282
  • 36. How does a Decision Tree work? Our second split will be on size as that will directly segregate the books Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle? E2 = 1.3784 E1 = 1.8282
  • 37. How does a Decision Tree work? Shape == Rectangle? Size>5? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 E3 = 0.716 E2 = 1.3784 E1 = 1.8282
  • 38. How does a Decision Tree work? Our third split will once again be on size Size>5? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle? E3 = 0.716 E2 = 1.3784 E1 = 1.8282
  • 39. How does a Decision Tree work? Size>3? Size>5? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle? E3 = 0.716 E2 = 1.3784 E1 = 1.8282 E4 = 0
  • 40. How does a Decision Tree work? Size>3? Size>5? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle? E2 = 1.3784 E3 = 0.716 E1 = 1.8282 E4 = 0
  • 41. How does a Decision Tree work? All our objects are now classified with 100% accuracy Size>3? Size>5? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle?
  • 42. How does a Decision Tree work? All our objects are now classified with 100% accuracy Size>3? Size>5? Shape Size Label Number round 10 ball 2 rectangle 6 book 2 rectangle 4 card 1 rectangle 2 blocks 4 total 9 Shape == Rectangle?
  • 43. Use Case: Survival prediction in R Let’s implement classification of a data set based on Information Gain
  • 44. Let’s implement classification of a data set based on Information Gain This is the ID3 algorithm Use Case: Survival prediction in R
  • 45. Let’s implement classification of a data set based on Information Gain This is the ID3 algorithm We will be using the RStudio IDE Use Case: Survival prediction in R
  • 46. • A ship had 20 lifeboats Use Case: Survival prediction in R
  • 47. • A ship had 20 lifeboats • The lifeboats were distributed based on the class, gender and age of the passengers Use Case: Survival prediction in R
  • 48. • A ship had 20 lifeboats • The lifeboats were distributed based on the class, gender and age of the passengers • We will develop a model that recognises the relationship between these factors and predicts the survival of a passenger accordingly Use Case: Survival prediction in R
  • 49. Use Case: Survival prediction in R We will be using a data set which specifies if a passenger on a ship survived it’s wreck or not
  • 50. 1 indicates the person survived the wreck We will be using a data set which specifies if a passenger on a ship survived it’s wreck or not Use Case: Survival prediction in R
  • 51. The luxury class of the cabin Use Case: Survival prediction in R We will be using a data set which specifies if a passenger on a ship survived it’s wreck or not
  • 52. Numbers of siblings on board Use Case: Survival prediction in R We will be using a data set which specifies if a passenger on a ship survived it’s wreck or not
  • 53. Numbers of parents on board Use Case: Survival prediction in R We will be using a data set which specifies if a passenger on a ship survived it’s wreck or not
  • 54. Disembark location Use Case: Survival prediction in R We will be using a data set which specifies if a passenger on a ship survived it’s wreck or not
  • 55. What is DecisionTree? Problems solved using DecisionTrees How does a decision tree work? Key Takeaways Predicting survivors using R Determining accuracy of prediction Terms to know

Editor's Notes