Decision Tree

Download Report

Transcript Decision Tree

Decision Tree
Decision Tree
• เรี ยกอีกชื่อว่า Classification tree
• เป็ นเทคนิคแบบ Supervised Learning
• เป็ นวิธีเรี ยนรู้ที่ไม่ซบั ซ้ อนมากนัก โดยมีโครงสร้ างเป็ นต้ นไม้ แตกแขนง
ไปตามเงื่อนไขหรื อข้ อมูลที่ได้ คาดคะเนไว้ วา่ จะเกิดขึ ้น
• โครงสร้ างของ Decision tree จะประกอบด้ วย
– ใบ (Leaf) เป็ นส่วนของผลลัพธ์ที่ได้
– กิ่ง (Branch) เป็ นตัวเชื่อมระหว่างโหนด
– ราก (Root) เป็ นจุดเริ่มต้ นของเหตุการณ์
ตัวอย่าง
root
branch
leaf
If outlook=sunny and humidity=normal then play=yes
If outlook=overcast then play=yes
If outlook=rainy and windy=false then play=yes
If outlook=sunny and humidity=high then play=no
If outlook=rainy and windy=true then play=no
Decision Tree
• การเรี ยนรู้ด้วย Decision tree เป็ นการเรี ยนรู้จากการคาดคะเน
เหตุการณ์ตา่ งๆที่อาจเกิดขึ ้น
• อาศัยเงื่อนไขเป็ นตัวช่วยในการตัดสินใจว่าเมื่อมีเหตุการณ์ ใดๆขึ ้น จะ
แสดงผลออกมาอย่างไร
• ต้ องการต้ นไม้ ให้ มีขนาดเล็ก
• การคาดคะเนจะถูกนาเสนอด้ วยรูปแบบการตัดสินใจ
(if/then/else)
– If outlook=overcast then play=yes
Information Gain
• ค่า Information gain ถูกนามาใช้ ในการเลือก attribute ใน
แต่ละ node ของ tree
• attribute ตัวใดทีมีคา่ Information gain สูงสุด จะถูกเลือก
Entropy
• Entropy หรื อ Information value
𝑒𝑛𝑡𝑟𝑜𝑝𝑦 𝑝1 , 𝑝2 , … , 𝑝𝑛 = −𝑝1 𝑙𝑜𝑔2 𝑝1 − 𝑝2 𝑙𝑜𝑔2𝑝2 … − 𝑝𝑛 𝑙𝑜𝑔2𝑝𝑛
𝑤ℎ𝑒𝑟𝑒 𝑝1 , + 𝑝2 +, … , +𝑝𝑛 = 1
หมายเหตุ:
2 3 4
info([2,3,4]) = entropy( , , )
9 9 9
2
2
3
3
= − 𝑙𝑜𝑔2 − 𝑙𝑜𝑔2
9
9
9
9
−
4
4
𝑙𝑜𝑔2
9
9
ตัวอย่างการคานวณค่า Entropy
info([9,5]) =
9 5
entropy( , )
14 14
info([2,3]) =
2 3
entropy( , )
5 5
info([4,0]) =
4 0
entropy( , )
4 4
info([3,2]) =
3 2
entropy( , )
5 5
= −
9
9
𝑙𝑜𝑔2
14
14
= −
2
2
𝑙𝑜𝑔2
5
5
3
3
− 𝑙𝑜𝑔2
5
5
= −
4
4
𝑙𝑜𝑔2
4
4
0
0
− 𝑙𝑜𝑔2
4
4
= −
3
3
𝑙𝑜𝑔2
5
5
2
2
− 𝑙𝑜𝑔2
5
5
−
5
5
𝑙𝑜𝑔2
14
14
ตัวอย่างการคานวณค่าเฉลี่ยของ information
info([2,3], [4,0], [3,2]) =
5
× 0.971
14
5
[ × 0.971]
14
= 0.693 bits
+
4
14
×0 +
ตัวอย่างการคานวณค่า Information Gain
Gain(outlook) = info([9,5]) - info([2,3], [4,0], [3,2])
= 0.940 – 0.693
= 0.247 bits
Information value of creating a branch on
the outlook attribute
[yes,no] = [9,5]
[2,3]
[4,0]
[3,2]
[2,2]
[4,2]
[3,1]
เลือกได้ 4 กรณี
Which is the best
choice?
[3,4]
[6,1]
[6,2]
[3,3]
[2,0]
[1,1]
[1,0]
[1,2]
[0,3]
[1,1]
[2,0]