A Step by Step ID3 Decision Tree Example by Niranjan Kumar Das
A Step by Step ID3 Decision Tree Example by Niranjan Kumar Das
These formulas might confuse your mind. Practicing will make it understandable.
Entropy
We need to calculate the entropy rst. Decision column consists of 14 instances and
includes two labels: yes and no. There are 9 decisions labeled yes, and 5 decisions labeled
no.
Wind attribute has two labels: weak and strong. We would re ect it to the formula.
Entropy(Decision|Wind=Strong) ]
There are 8 instances for weak wind. Decision of 2 items are no and 6 items are yes as
illustrated below.
Notice that if the number of instances of a class were 0 and total number of instances
were n, then we need to calculate -(0/n) . log2(0/n). Here, log(0) would be equal to - ∞, and
we cannot calculate 0 times ∞. This is a special case often appears in decision tree
applications. Even though compilers cannot compute this operation, we can compute it
with calculus. If you wonder how to compute this equation, please read this post.
Here, there are 6 instances for strong wind. Decision is divided into two equal parts.
Calculations for wind column is over. Now, we need to apply same calculations for other
As seen, outlook factor on decision produces the highest score. That’s why, outlook
1- Gain(Outlook=Sunny|Temperature) = 0.570
2- Gain(Outlook=Sunny|Humidity) = 0.970
3- Gain(Outlook=Sunny|Wind) = 0.019
Now, humidity is the decision because it produces the highest score if outlook were sunny.
On the other hand, decision will always be yes if humidity were normal
Finally, it means that we need to check the humidity and decide if outlook were sunny.
Ad loxleycolour.com More ▼
Here, wind produces the highest score if outlook were rain. That’s why, we need to check
So, it is revealed that decision will always be yes if wind were weak and outlook were rain.
What’s more, decision will be always no if wind were strong and outlook were rain.
So, decision tree construction is over. We can use the following rules for decisioning.
Feature Importance
Decision trees are naturally explainable and interpretable algorithms. Besides, we can nd