1 / 35

หน่วยที่ 6 Association Rule : FP-Tree & FP Growth

หน่วยที่ 6 Association Rule : FP-Tree & FP Growth. อ.วิวัฒน์ ชินนาทศิริกุล. ปัญหาของ Apriori Algorithm. 1. ไม่เหมาะกับการทำงานกับข้อมูลจำนวนมากๆ หรือฐานข้อมูลขนาด ใหญ่ เนื่องจากต้องสร้าง candidate item set จำนวนมาก เช่น

stian
Download Presentation

หน่วยที่ 6 Association Rule : FP-Tree & FP Growth

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. หน่วยที่ 6 Association Rule : FP-Tree & FP Growth อ.วิวัฒน์ ชินนาทศิริกุล

  2. ปัญหาของ Apriori Algorithm 1. ไม่เหมาะกับการทำงานกับข้อมูลจำนวนมากๆ หรือฐานข้อมูลขนาด ใหญ่ เนื่องจากต้องสร้าง candidate item set จำนวนมากเช่น 104 frequent 1-itemset will generate 107 candidate 2-itemsets 2. มีการอ่านข้อมูลจากฐานข้อมูลหลายครั้ง เนื่องจากทุกครั้งที่ต้องการ ตรวจสอบว่า candidate items set เป็น frequent items set หรือไม่ จะต้องอ่านข้อมูลจากฐานข้อมูลเพื่อหาความถี่

  3. จากปัญหาที่เกิดจาก Ariori Algorithm ทำให้มีการคิดวิธีการปรับปรุงประสิทธิภาพ การทำงานที่หา frequent itemsets โดยไม่ต้องสร้าง candidate itemsets ขึ้น วิธีการหนึ่งที่น่าสนใจที่สามารถสร้าง frequent itemsets โดยไม่ต้องสร้าง Candidate คือ Frequent Pattern growth หรือเรียกย่อๆว่า FP-growth วิธีการนี้ประกอบด้วย ขั้นตอนแรก – แสดง Frequent itemsets ด้วย Frequent-pattern-Tree (FP-Tree) ขั้นตอนถัดไป – สร้างเซตของ conditional base pattern แล้วนำค่าที่ได้ไปหา frequent itemsets

  4. FP-Tree Definition FP-tree มาจากคำว่า frequent pattern treeโครงสร้าง FP-tree นิยามไว้ ดังนี้ 1. Root Node แทนค่าด้วย “null", ลูกของ Root จะเป็นเซตของ item ต้นไม้ ย่อย 2. แต่ละโหนดใน ต้นไม้ย่อย มี 3 ฟิลด์ • item-name :แทนค่าของโหนดที่แสดงผล • Count จำนวน transaction เมื่อนับถึงโหนดที่กำหนด • node-linkใช้เชื่อมโยง node ใน FP-tree ที่มีชื่อเดียวกัน หรือค่า null

  5. FP-Tree Definition (ต่อ) 3. ตาราง header มี 2 ฟิลด์ • ชื่อ item และ • head of node-link ที่ชี้ไปยังโหนดแรกใน FP-tree

  6. ตัวอย่าง FP-Tree null Header Table Item head f c a b m p f:4 c:1 c:3 b:1 b:1 a:3 p:1 m:2 b:1 p:2 m:1

  7. การสร้าง FP-Tree มี 2 ขั้นตอน 1. อ่านค่า Transaction ในฐานข้อมูล เพื่อหาค่าความถี่ หรือค่า support ของแต่ละ item และเรียงลำดับ item ตามค่าความถี่จากมากไปหาน้อย ใส่ใน List เช่น Item frequency f 4 c 4 a 3 b 3 m 3 p 3

  8. การสร้าง FP-Tree (ต่อ) 2. ในแต่ละ transaction ให้เรียงลำดับ items ตามความถี่ของ item ใน List จากนั้นให้อ่านฐานข้อมูล ครั้งที่ 2 เพื่อสร้าง FP-Tree โดยนำค่า items ที่เรียงลำดับความถี่ในแต่ละ Transaction ใส่ใน FP-Tree

  9. ตัวอย่าง การสร้าง FP-Tree กำหนด Transactions ในการซื้อสินค้า ดังตารางด้านล่าง ให้สร้าง FP-Tree โดยกำหนด Minimum Support อย่างน้อย 3 transaction TID Items bought 100 {f, a, c, d, g, i, m, p} 200 {a, b, c, f, l, m, o} 300 {b, f, h, j, o} 400 {b, c, k, s, p} 500{a, f, c, e, l, p, m, n}

  10. ตัวอย่าง การสร้าง FP-Tree (ต่อ) 1. อ่าน transactions จากฐานข้อมูล ครั้งที่ 1 เพื่อหาความถี่ ของแต่ละ items เรียงลำดับจากความถี่มากไปหาความถี่น้อย เพื่อสร้าง list L L Item frequency f 4 c 4 a 3 b 3 m 3 p 3

  11. ตัวอย่าง การสร้าง FP-Tree (ต่อ) 2. อ่าน transactions ในฐานข้อมูล ครั้งที่ 2 เพื่อเรียงลำดับ items ในแต่ละ transactions ตามความถี่ ตาม list L TID Items bought (ordered) frequent items 100 {f, a, c, d, g, i, m, p}{f, c, a, m, p} 200 {a, b, c, f, l, m, o}{f, c, a, b, m} 300 {b, f, h, j, o}{f, b} 400 {b, c, k, s, p}{c, b, p} 500{a, f, c, e, l, p, m, n}{f, c, a, m, p}

  12. ตัวอย่าง การสร้าง FP-Tree (ต่อ) สร้าง FP-Tree จาก (ordered) frequent items null f:1 TID=100 {f, c, a, m, p} c:1 a:1 NOTE: Each transaction corresponds to one path in the FP-tree m:1 p:1

  13. ตัวอย่าง การสร้าง FP-Tree (ต่อ) null null f:1 f:2 TID=100 {f, c, a, m, p} TID=200 {f, c, a, b, m} c:1 c:2 a:1 a:2 b:1 m:1 m:1 m:1 p:1 p:1 Node-Link

  14. ตัวอย่าง การสร้าง FP-Tree (ต่อ) null null null f:3 c:1 f:3 f:4 c:1 TID=400 {c, b, p} TID=300 {f, b} TID=500 {f, c, a, m, p} c:2 b:1 b:1 c:2 c:3 b:1 b:1 b:1 a:2 p:1 a:2 a:3 p:1 m:1 b:1 m:1 b:1 m:2 b:1 p:1 m:1 p:1 m:1 p:2 m:1

  15. ตัวอย่าง การสร้าง FP-Tree (ต่อ) null Final FP-tree Header Table Item head f c a b m p f:4 c:1 c:3 b:1 b:1 a:3 p:1 m:2 b:1 p:2 m:1

  16. การสร้าง Frequent itemsets จาก FP-Tree • สร้าง Prefix Path Subtree ของ items ที่ต้องการ • สร้าง Conditional Base Pattern • สร้าง Frequent Pattern

  17. 1. สร้าง Prefix Path Subtree ของ items ที่ต้องการ Prefix path subtree of m Prefix path subtree of b Prefix path subtree of p null null null f:4 c:1 f:4 c:1 f:4 c:3 b:1 b:1 c:3 b:1 c:3 a:3 a:3 p:1 a:3 m:2 m:2 b:1 b:1 p:2 m:1

  18. Prefix path subtree of a Prefix path subtree of c Prefix path subtree of f null null null f:4 f:4 c:1 f:4 c:3 c:3 a:3

  19. Items prefix path subtree p {f:4,c:3,a:3,m:2,p:2} {c:1,b:1,p:1} m {f:4,c:3,a:3,m:2} {f:4,c:3,a:3,b:1,m:1} b {f:4,c:3,a:3,b:1} {f:4,b:1} {c:1,b:1} a {f:4,c:3,a:3} c {f:4,c:3} {c:1} f {f:4} Prefix Path Subtree แต่ละโหนดที่ได้

  20. Items prefix path subtree p {f:4,c:3,a:3,m:2,p:2} {c:1,b:1,p:1} m {f:4,c:3,a:3,m:2} {f:4,c:3,a:3,b:1,m:1} b {f:4,c:3,a:3,b:1} {f:4,b:1} {c:1,b:1} a {f:4,c:3,a:3} c {f:4,c:3} {c:1} f {f:4} นำ Prefix path subtree มาหา Condition Base Pattern Condition Tree { c : 3 } { f c a : 3} - { f c :3 } { f :3} null Condition base pattern {f c a m :2} {c b :1} {f c a :2} {f c a b :1} {f c a :1} {f :1} {c b :1} {f c :3} {f :3} null

  21. พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด pคือ { c : 3 } นำไปสร้าง itemsets ขนาด 1-itemset 2-itemsets 3-itemset ไปเรื่อยๆ ดังนี้ 1-items 2-items p cp นำ Condition FP-Tree ไปสร้าง Frequent itemsets  null f:4 c:1 c:3 b:1 b:1 a:3 p:1 Frequent itemsets ที่ได้คือ {p} {cp} m:2 b:1 p:2 m:1

  22. นำ Condition FP-Tree ไปสร้าง Frequent itemsets (ต่อ) null พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด mคือ {f c a : 3 } นำไปสร้าง itemsets ขนาด 1-itemset 2-itemsets 3-itemset ไปเรื่อยๆ ดังนี้ 1-items 2-items3-items 4-items m am cam fcam fam cm fcm fm f:4 c:1 c:3 b:1 b:1 a:3 p:1 m:2 b:1 Frequent itemsets ที่ได้คือ {m} {am} {cam} {fcam} {fam} {cm} {fcm} {fm} p:2 m:1

  23. 1-items 2-items 3-items a cafca fa นำ Condition FP-Tree ไปสร้าง Frequent itemsets (ต่อ) null พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด bคือ {} Frequent itemsets ที่ได้คือ {b} f:4 c:1 c:3 b:1 b:1 พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด aคือ { f c :3} a:3 p:1 m:2 b:1 p:2 m:1 Frequent itemsets ที่ได้คือ {a}{ca} {fca} {fa}

  24. นำ Condition FP-Tree ไปสร้าง Frequent itemsets (ต่อ) null พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด cคือ { f:3} Frequent itemsets ที่ได้คือ {c} {fc} f:4 c:1 c:3 b:1 b:1 พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด fคือ {} Frequent itemsets ที่ได้คือ {f} a:3 p:1 m:2 b:1 p:2 m:1

  25. สรุป Frequent itemsets ที่ได้ {p} {cp} {m} {am} {cam} {fcam} {fam} {cm} {fcm} {fm} {b}{a} {ca} {fca} {fa} {c} {fc} {f}

  26. ตัวอย่างที่ 2 จงสร้าง FP-Tree และหา Frequent itemsets ทั้งหมด กำหนด min_support ไม่น้อยกว่า 2 transaction

  27. Bubble Jet 3 CD Writer 3 DVD Rom 3 Film 2 วิธีทำ 1. หาจำนวนความถี่ ของแต่ละ item ได้ดังนี้ Apple Mac 1 Bubble Jet 3 CD Writer 3 DVD Rom 3 E-Business S/w 1 Film 2 Graphic Card1

  28. TID item bought • Bubble Jet , CD Writer • CD Writer , DVD Rom • 3 Bubble Jet, DVD Rom, Film • 4 Bubble Jet, CD Writer, DVD Rom, Film 2. เรียงลำดับ items ในแต่ละ transaction ใหม่ และตัด items ที่ ค่า support น้อยกว่า 2 ทิ้ง

  29. null C:1 B:3 Bubble Jet 3 CD Writer 3 DVD Rom 3 Film 2 D:1 C:2 D:1 D:1 F:1 F:1 3. สร้าง FP-Tree จาก transactions ในข้อ 2

  30. Item prefix path subtree condition FP-tree F {b:3 c:2 d:1 f:1} {b:3 d:1 f:1} {b:2 d:2} D {b:3 c:2 d:1} {b:3 d:1} {c:1 d:1} {b:2 c:2} C {b:3 c:2} {c:1} {b:2} B{b:3} {} 4. หา prefix path subtree และ condition base FP-Tree

  31. null C:1 B:3 D:1 C:2 D:1 D:1 F:1 F:1 5. หา Frequent itemsets ของแต่ละโหนด พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด F คือ { B:2 D:2 } นำไปสร้าง itemsets ดังนี้ 1-items 2-items 3-items F DF BDF BF Frequent itemsets ที่ได้คือ {F} {DF}{BDF} {BF}

  32. null C:1 B:3 D:1 C:2 D:1 D:1 F:1 F:1 พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด D คือ { B:2 C:2 } นำไปสร้าง itemsets ดังนี้ 1-items 2-items 3-items D CD BCD BD Frequent itemsets ที่ได้คือ {D} {CD}{BD}

  33. null C:1 B:3 D:1 C:2 D:1 D:1 F:1 F:1 พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด C คือ { B:2 } นำไปสร้าง itemsets ดังนี้ 1-items 2-items C BC Frequent itemsets ที่ได้คือ {C} {BC}

  34. พิจารณา จาก Condition FP-Tree ที่มีฐานเป็นโหนด B คือ {} Frequent itemsets ที่ได้คือ {B} สรุปFrequent itemsets ทั้งหมดที่ได้คือ {F} {DF}{BDF} {BF} {D} {CD}{BD} {C} {BC}{B} {Film} {DVD Rom} {CD Writer} {Bubble Jet} {DVD Rom , Film} {Bubble Jet , Film} {CD Writer , DVD Rom} {Bubble Jet , DVD Rom} {Bubble Jet , CD Writer} {Bubble Jet , DVD Writer , Film}

  35. แบบฝึกหัด จงสร้าง FP-Tree และหา Frequent itemsets ทั้งหมดที่ได้ กำหนด Minimum Support=33.34%

More Related