file 498 doc 18 04dm associationrules
TRANSCRIPT
![Page 1: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/1.jpg)
1
ผู้��ช่�วยศาสตราจารย�จ�ร�ฎฐา ภู�บุ�ญอบุ ([email protected],
08-9275-9797)
ASSOCIASSOCIATIONATIONRULESRULES
![Page 2: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/2.jpg)
2
1. Affinity Analysis and Market Basket Analysis
Customer1
Milk, eggs, sugar, bread
Customer2
Milk, eggs, cereal, bread
Customer3
Eggs, sugar, bread
![Page 3: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/3.jpg)
3
1. Affinity Analysis and Market Basket Analysis (cont’d)
ในธุ�รกิ�จกิารขายลู�กิค้�าค้ อผู้��ซื้ "อส�นค้�าหร อบุร�กิารจากิบุร�ษั�ท ซื้&'งอาจจะมี+พฤต�กิรรมีกิารซื้ "อท+'แตกิต�างกิ�นไปผู้��บุร�หารต�องกิารว�เค้ราะห�ข�อมี�ลูกิารซื้ "อส�นค้�าท+'เกิ�ดพร�อมีกิ�น หร อไมี�เกิ�ดพร�อมีกิ�น ต�องกิารทราบุ
พฤต�กิรรมีของกิารซื้ "อขายท+'ไมี�เฉพาะเจาะจงลู�กิค้�าค้นหน&'งค้นใดลู�กิษัณะของส�นค้�าหร อผู้ลู�ตภู�ณฑ์�ท+'ถู�กิซื้ "อค้��กิ�นลู�กิษัณะกิารซื้ "อขายท+'แตกิต�างกิ�บุส�นค้�าอ 'น
เพ 'อน7ามีาวางแผู้นลู�กิษัณะกิารด7าเน�นธุ�รกิ�จจากิค้วามีร� �ท+'ได�
![Page 4: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/4.jpg)
4
1. Affinity Analysis and Market Basket Analysis (cont’d)
ผู้��บุร�หารใช่�ข�อมี�ลูเหลู�าน+"เพ 'อบุ�งบุอกิพฤต�กิรรมีของลู�กิค้�าท�'วไปเข�าใจลู�กิษัณะพฤต�กิรรมีท+'น7ามีาใช่�ประโยช่น�ได�เข�าใจผู้ลู�ตภู�ณฑ์�
ขายเร9ว กิ�บุขายช่�าส�นค้�าท+'ซื้ "อไปด�วยกิ�นส�นค้�าท+'อาจได�ประโยช่น�จากิกิารสน�บุสน�นกิารขาย
ประย�กิต�เพ 'อเพ�'มียอดขายกิารวางผู้�งภูายในร�านกิารน7าส�นค้�ามีาลูด แลูกิ แจกิ แถูมี
![Page 5: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/5.jpg)
5
1. Affinity Analysis and Market Basket Analysis (cont’d)
เทค้น�ค้ท+'ใช่�ในกิารว�เค้ราะห�ด�งกิลู�าว ค้ อ กิฎเช่ 'อมีโยงท+'เน�นกิารใช่�ข�อมี�ลูจากิ point-of-sale (p-o-s)ข�อมี�ลูท+'น7ามีาใช่�ว�เค้ราะห�อย��ในร�ปของ transaction
รห�สกิารซื้ "อหน&'งใบุเสร9จข�อมี�ลูลู�กิษัณะลู�กิค้�า (ถู�ามี+)ปร�มีาณส�นค้�าท+'ซื้ "อข�อมี�ลูประเภูทของส�นค้�าท+'ขายจ7านวนเง�น
![Page 6: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/6.jpg)
6
1. Affinity Analysis and Market Basket Analysis (cont’d)ลู�กิษัณะค้7าถูามีท+'ส7าค้�ญเกิ+'ยวกิ�บุกิารขาย
ผู้��ซื้ "อปฏิ�เสธุหร อยอมีร�บุกิารพยายามีขายส�นค้�าต�างลู�กิษัณะหร อไมี�?ส�นค้�าใดท+'ปรากิฎร�วมีกิ�นบุ�อยในหน&'งใบุเสร9จ?อะไรค้ อส�นค้�าท+'พบุว�าถู�กิขายบุ�อยให�กิ�บุลู�กิค้�าท+'มีาร�บุบุร�กิารซื้7"าๆ ?ลู�กิษัณะกิารขายของส�นค้�ามี+กิารเปลู+'ยนไปตามีเวลูาหร อไมี� ?ลู�กิษัณะกิารขายของส�นค้�าเปลู+'ยนไปตามีท+'อย��ของลู�กิค้�าหร อไมี� อย�างไร?
![Page 7: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/7.jpg)
7
1. Affinity Analysis and Market Basket Analysis (cont’d)Market Basket data analysis, cross-marketing, catalog design, sale campaign analysisQuantify relationships in the form of Rules
IF antecedent THEN consequentRules measured using support and confidenceDiscover which items in supermarket are purchased together
Thursday night 200 of 1,000 customers bought diapers, and of those buying diapers, 50 purchased beerAssociation Rule: “IF buy diapers, THEN buy beer”Support = 50/1,000 = 5%, and confidence = 50/200 = 25%
![Page 8: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/8.jpg)
8
2. Support and Confidence
Support (ค้�าสน�บุสน�น ) ของกิฎ diapers beer ค้ อค้วามีน�าจะเป<นท+'จะพบุกิารซื้ "อท+'มี+ท�"ง diapers แลูะ beerConfidence (ค้�าค้วามีเช่ 'อมี�'น ) ของกิฎ diapers beer ค้ อค้วามีน�าจะเป<นแบุบุมี+เง 'อนไขท+'พบุว�ามี+กิารซื้ "อ diapers แลู�วจะซื้ "อ beer
Customerbuys
diapers
Customerbuys both
Customerbuys beer
1,000
![Page 9: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/9.jpg)
9
2. Support and Confidence (cont’d)The support for a particular association rule A B is the proportion of transactions that contain both A and B. That is,
The confidence of the association rule A B is
![Page 10: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/10.jpg)
10
2. Support and Confidence (cont’d)
กิฎท+'เป<นไปได�ของส�นค้�าสองช่น�ดค้ อ
จ7านวนกิฎท+'เป<นไปได�ท�"งหมีด = (k= รายกิารส�นค้�า)กิฎ P P เป<นกิฎท+'ไมี�น�าสนใจ เพราะเป<นกิฎท+'จร�งเสมีอส7าหร�บุท�กิค้�า Pใช่�ค้�าต7'าส�ดของค้�าสน�บุสน�นกิ�บุค้�าค้วามีเช่ 'อมี�'นกิ7าหนดค้วามีน�าสนใจ ค้ อกิฏิท+'มี+ค้�าสน�บุสน�น min support แลูะค้�าค้วามีเช่ 'อมี�'น min confidence เป<นกิฎท+'น�าสนใจ แลูะเซื้ตของกิลู��มีส�นค้�าท+'มี+ค้�าสน�บุสน�น min support เร+ยกิว�า frequent itemset
12 kk
AB, BA, CA, DA, EA, FAAC, BC, CB, DB, EB, FBAD, BD,CD, DC, EC, FCAE, BE, CE, DE, ED, FDAF, BF, CF, DF, EF, FE
![Page 11: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/11.jpg)
11
กิารหา frequent itemset ซื้&'ง frequent itemset ค้ อกิลู��มีของ item ท+'มี+ค้�าสน�บุสน�นมีากิกิว�าหร อเท�ากิ�บุค้�า minimum support
ส�บุเซื้ตของ frequent itemset เป<น frequent itemset ค้ อ ถู�า {A,B} เป<น frequent itemset แลู�ว {A} แลูะ {B} ต�องเป<น frequent itemsetฉะน�"นกิารหา frequent itemset ท+'มี+ k ต�ว ท7าได�จากิกิารพ�จารณา k-1 ต�ว กิลู�าวค้ อเราหา frequent itemset จากิ 1 ไปถู&ง k
หลู�งจากิท+'พ�จารณาท�กิ frequent itemset ท+'มี+จ7านวนมีากิท+'ส�ดแลู�ว เราสร�างกิฎเช่ 'อมีโยงจากิ frequent itemset ท�"งหมีดท+'ได�กิฏิท+'ได�จะมี+ consequent เพ+ยง 1 data field เท�าน�"น น�'นค้ อIF _____, ______, _____ THEN ______
3. The Apriori Algorithm (cont’d)
![Page 12: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/12.jpg)
12
2. Support and Confidence (cont’d)
TABLE 10.1 Transactions Made at the Roadside Vegetable StandTransaction Items Purchased 1 Broccoli, green peppers, corn 2 Asparagus, squash, corn 3 Corn, tomatoes, beans, squash 4 Green peppers, corn, tomatoes, beans 5 Beans, asparagus, broccoli 6 Squash, asparagus, beans, tomatoes 7 Tomatoes, corn 8 Broccoli, tomatoes, green peppers 9 Squash, asparagus, beans 10 Beans, corn 11 Green peppers, broccoli, beans, squash 12 Asparagus, beans, squash 13 Squash, corn, asparagus, beans 14 Corn, green peppers, tomatoes, beans, broccoli
![Page 13: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/13.jpg)
13
2. Support and Confidence (cont’d)
![Page 14: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/14.jpg)
14
3. The Apriori AlgorithmPseudo-code:
Ck: Candidate itemset of size kLk : frequent itemset of size k
L1 = {frequent items};for (k = 1; Lk ; k++) do begin Ck+1 = candidates generated from Lk; for each transaction t in database do
increment the count of all candidates in Ck+1 that are contained in t
Lk+1 = candidates in Ck+1 with min_support
endreturn k Lk;
![Page 15: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/15.jpg)
15
3. The Apriori Algorithm (cont’d)
1st scan
C1 L1
L2
C2 C2
2nd scan
C3 L33rd scan
Tid
Items
10
A, C, D
20
B, C, E
30
A, B, C, E
40
B, E
Itemset
sup
{A} 2
{B} 3
{C} 3
{D} 1
{E} 3
Itemset
sup
{A} 2
{B} 3
{C} 3
{E} 3
Itemset
{A, B}
{A, C}
{A, E}
{B, C}
{B, E}
{C, E}
Itemset
sup
{A, B} 1{A, C} 2{A, E} 1{B, C} 2{B, E} 3{C, E} 2
Itemset
sup
{A, C} 2{B, C} 2{B, E} 3{C, E} 2
Itemset
{B, C, E}
Itemset
sup
{B, C, E}
2
Supmin = 2
![Page 16: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/16.jpg)
16
3. The Apriori Algorithm (cont’d)
How to generate candidates?Step 1: self-joining LkStep 2: pruning
How to count supports of candidates?Example of Candidate-generation
L3={abc, abd, acd, ace, bcd}Self-joining: L3*L3
abcd from abc and abdacde from acd and ace
Pruning:acde is removed because ade is not in L3C4={abcd}
![Page 17: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/17.jpg)
17
4. ปั�ญหาของข�นตอนวิ�ธี� Apriori
ค้+ย�หลู�กิของข�"นตอนว�ธุ+ Aprioriใช่� frequent (k-1) itemsets สร�าง candidate frequent k- itemsetsอ�าน database แลูะทดสอบุร�ปแบุบุเพ 'อน�บุแลูะลูด candidate itemset
ป=ญหาค้อขวดของข�"นตอนว�ธุ+ Apriori: กิารสร�าง candidate
ปร�มีาณ candidate ท+'มีากิเกิ�นไป10
4 frequent 1-itemset สร�างได� 10 7candidate 2-itemsetsกิารค้�น frequent pattern ขนาดใหญ� เช่�น {a1, a2, …,a100} เราต�องสร�าง 2100 1030 candidates
มี+กิารอ�าน database หลูายรอบุต�องกิาร (n+1) scans เมี 'อ n ค้ อค้วามียาวของ pattern
![Page 18: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/18.jpg)
18
5. FP-Growth Algorithm
Mining frequent patterns without candidate generation3 เทค้น�ค้หลู�กิเพ 'อเพ�'มีประส�ทธุ�ภูาพให�กิ�บุกิารหา Frequent itemsets ค้ อ 1 . บุ+บุอ�ดข�อมี�ลูจากิฐานข�อมี�ลูส��หน�วยค้วามีจ7าในร�ปแบุบุ FP-tree (Frequent Pattern tree ) เพ 'อหลู+กิเลู+'ยงกิารอ�านฐานข�อมี�ลูซื้7"าหลูายรอบุ 2 . ด�วยโค้รงสร�าง FP-tree ท7าให�ไมี�ต�องสร�าง candidate sets ขนาดใหญ�3 . ใช่�ลู�กิษัณะกิารท7างานแบุบุแบุ�งส�วน แบุ�งงานให�เลู9กิลูงเพ 'อกิารเปร+ยบุเท+ยบุท+'น�อยลูง แลูะช่�วยลูดเวลูาในกิารค้�นหาเพราะท7าในพ "นท+'ท+'เลู9กิลูง
![Page 19: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/19.jpg)
19
5. FP-Growth Algorithm (cont’d)
1. The set of frequent 1-itemsets together with support counts is found. (L1) 2. Sort the elements in the set of frequent items in the order of descending support count (f-list)
3. Construct FP-TreeCreate the root of the tree, labeled with { }Scan DB D. The items in each T are processed in L order
4. Mine the FP-treeMining the FP-tree by creating conditional (sub) pattern bases
5. Generate rules
![Page 20: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/20.jpg)
20
5. FP-Growth Algorithm (cont’d)
{}
f:4 c:1
b:1
p:1
b:1c:3
a:3
b:1m:2
p:2 m:1
Header Table
Item frequency head f 4c 4a 3b 3m 3p 3
min_support = 3
TID Items bought (ordered) frequent items100 {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, w} {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}
1. Scan DB once, find frequent 1-itemset (single item pattern)
2. Sort frequent items in frequency descending order, f-list
3. Scan DB again, construct FP-tree
F-list=f-c-a-b-m-p
![Page 21: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/21.jpg)
21
6. Generating Association Rules
IF antecedent THEN consequent (support, confidence)
ต�องด�ว�า antecedent จะให�มี+กิ+'เง 'อนไข ในแง�ของ market ค้ อจะให�มี+ส�นค้�ากิ+'รายกิาร ซื้&'ง user จะต�องเป<นค้นบุอกิ จากิต�วอย�าง (Apriori) กิฎท+'ยาวท+'ส�ดค้ อ L3 ซื้&'งมี+ได� 2 antecedent เน 'องจากิมี+ส�นค้�า 3รายกิารจะได�กิฎว�า
B,C EB,E CC,E B
Support = 4
2},,{
n
ECBn
![Page 22: File 498 Doc 18 04dm Associationrules](https://reader036.vdocuments.pub/reader036/viewer/2022081514/555cca0fd8b42a5f718b57c1/html5/thumbnails/22.jpg)
22
6. Generating Association Rules (cont’d)
2
2
},{
},,{ Rule1 Confidence
CBn
ECBn
3
2
},{
},,{ Rule2 Confidence
EBn
ECBn
2
2
},{
},,{ Rule3 Confidence
ECn
ECBn
B,C E (50%, 100%)B,E C (50%, 67%)C,E B (50%, 100%)