ML intro
ML intro
Splitting Attributes
Tid Refund Marital Taxable
Status Income Cheat
• If you want to draw a decision tree using ID3 Algorithm, we need to understand
which attribute gives the maximum available information.
• The one which has the maximum information gain will be treated as the root
node.
Steps in ID3
1. Compute the entropy for the entire Data-set [ Entropy (S)]
2. For Every attribute / Feature
1. Calculate the Entropy [ Entroty (A)]
2. Calculate Average Information current attribute
3. Calculate Gain for the current attribute
• Total Instances = 14
• Number of Positive Instances (p)= 09
• Number of Negative Instances (n) = 05
Calculate the Entropy of each attribute followed by
the information gain
• Let us start with Attribute ( Outlook)
Outlook Entropy
Sunny 0.971
Rainy 0.971
Overcast 0
Calculate Average Information Entropy
𝑃𝑠𝑢𝑛𝑛𝑦 + 𝑛𝑠𝑢𝑛𝑛𝑦
∗ 𝐸𝑛𝑡𝑟𝑜𝑝𝑦(𝑜𝑢𝑡𝑙𝑜𝑜𝑘 = 𝑠𝑢𝑛𝑛𝑦 +
𝑃𝑡𝑜𝑡𝑎𝑙 + 𝑛 𝑡𝑜𝑡𝑎𝑙
𝑃𝑟𝑎𝑖𝑛𝑦 + 𝑛𝑟𝑎𝑖𝑛𝑦
𝑰(𝑶𝒖𝒕𝒍𝒐𝒐𝒌) = ∗ 𝐸𝑛𝑡𝑟𝑜𝑝𝑦(𝑜𝑢𝑡𝑙𝑜𝑜𝑘 = 𝑟𝑎𝑖𝑛𝑦 +
𝑃𝑡𝑜𝑡𝑎𝑙 + 𝑛 𝑡𝑜𝑡𝑎𝑙
𝑃𝑜𝑣𝑒𝑟𝑐𝑎𝑠𝑡 + 𝑛𝑜𝑣𝑒𝑟𝑐𝑎𝑠𝑡
∗ 𝐸𝑛𝑡𝑟𝑜𝑝𝑦(𝑜𝑢𝑡𝑙𝑜𝑜𝑘 = 𝑜𝑣𝑒𝑟𝑐𝑎𝑠𝑡
𝑃𝑡𝑜𝑡𝑎𝑙 + 𝑛 𝑡𝑜𝑡𝑎𝑙
2 2 2 2
S 𝑻𝒆𝒎𝒑𝒆𝒓𝒂𝒕𝒖𝒓𝒆𝑯𝒐𝒕 = − 𝐿𝑜𝑔2 − 𝐿𝑜𝑔2
2 2 2 2
4 4 2 2
S 𝑻𝒆𝒎𝒑𝒆𝒓𝒂𝒕𝒖𝒓𝒆𝒎𝒊𝒍𝒅 = − 𝐿𝑜𝑔2 − 𝐿𝑜𝑔2
6 6 6 6
3 3 1 1
S 𝑻𝒆𝒎𝒑𝒆𝒓𝒂𝒕𝒖𝒓𝒆𝑪𝒐𝒍𝒅 = − 𝐿𝑜𝑔2 − 𝐿𝑜𝑔2
4 4 4 4
𝑻𝒆𝒎𝒑𝒆𝒓𝒂𝒕𝒖𝒓𝒆 Entropy
Hot 1
Mild 0.918
Cool 0.811
Calculate Average Information Entropy
𝑰(𝑻𝒆𝒎𝒑) = 0.911
Total Instances = 7
Total Instances = 7 Positive (p) = 06
Positive (p) = 3 Negative (n) = 01
Negative (n) = 4
Calculate Entropy (S) of Attribute Humidity
2 2 2 2
S 𝑯𝒖𝒎𝒊𝒅𝒊𝒕𝒚𝑵𝒐𝒓𝒎𝒂𝒍 = − 𝐿𝑜𝑔2 − 𝐿𝑜𝑔2
2 2 2 2
4 4 2 2
S 𝑯𝒖𝒎𝒊𝒅𝒊𝒕𝒚 𝒉𝒊𝒈𝒉 = − 𝐿𝑜𝑔2 − 𝐿𝑜𝑔2
6 6 6 6
𝑻𝒆𝒎𝒑𝒆𝒓𝒂𝒕𝒖𝒓𝒆 Entropy
Normal 0.985
High 0.591
Calculate Average Information Entropy
3+4 6+1
𝑰(𝑯𝒖𝒎𝒊𝒅𝒊𝒕𝒚) = ∗ 0.985 + ∗ 0.591
9+5 9+5
𝑰(𝑯𝒖𝒎𝒊𝒅𝒊𝒕𝒚) = 0.788
Attributes Gain
Outlook 0.247
Temp 0.029
Humidity 0.152
Windy 0.048
Naïve Bayes Classifier
Predict the outcome for the following Scenarios using Naïve Bayes
Classifier
Outlook Yes No
overcast 4/9 0
Temp Yes No
Mild 4/9 0
Outlook= Sunny
Temperature = Cool
Humidity= High
Wind= Strong
Predicting the outcome for the scenario-2 using Naïve Bayes
Classifier
Outlook= Rain
Temperature = Cool
Humidity= High
Wind= Strong