SlideShare a Scribd company logo
1 of 38
Download to read offline
關聯聯規則分析
Association Rules Analysis
on Spark
MLlib - Frequent Pattern Mining
Gil

2018-08-31
outline
• Introduction to Association Rules

• Association Rules on Distributed Computing (Spark)

• 案例例:旅遊關聯聯分析

• 案例例:競價關聯聯分析
Introduction to
Association Rules
莫再提了了!啤酒尿尿布是都市傳說 Chih-Cheng Liang, Nov, 2016
example
A B C D E
ㄎㄎ V V V
遙遙 V V V V
叮叮 V V
A  B
Support  P(A B):A 與 B 共同出現的機率,數值越⼤大越好。

Confidence  P(B|A):在 A 出現的前提下,出現 B 的機率,數值越⼤大越好。

Lift P(B|A)/P(B):B 單獨出現比率與前項 Confidence 的比較,
當數值⼤大於 1 表⽰示規則有效,數值越⼤大效果越好。
∩
user item
ㄎㄎ A
ㄎㄎ B
ㄎㄎ E
遙遙 A
叮叮 B
[ A, B, E ]

[ A, B, C, E ]

[ A, B ]
transactions
+---------+----+
| items|freq|
+---------+----+
| [A]| 3|
| [B]| 3|
| [B, A]| 3|
| [E]| 2|
| [E, B]| 2|
|[E, B, A]| 2|
| [E, A]| 2|
+---------+----+
+----------+----------+------------+
|antecedent|consequent| confidence|
+----------+----------+------------+
| [E]| [B]| 1.0|
| [E]| [A]| 1.0|
| [B, A]| [E]|0.6666666666|
| [E, B]| [A]| 1.0|
| [A]| [B]| 1.0|
| [A]| [E]|0.6666666666|
| [E, A]| [B]| 1.0|
| [B]| [A]| 1.0|
| [B]| [E]|0.6666666666|
+----------+----------+------------+
Apriori Algorithm
• 所有項⽬目集合中,若若某項⽬目集合的頻次很低,則該⺟母集合也很低。

• e.q. 消費記錄中,購買「林林X營鮮乳」的 transaction 很少,則
item sets 組合中出現前品項者,都會先被排除。
[ A, B, E ]

[ A, B, C, E ]

[ A, B ]
transactions
n = 4

item sets = 24 - 1 = 15

4: {A}, {B}, {C}, {E}

6: {A,B}, {A,C}, {A,E}, {B,C}, {B,E}, {C,E}

4: {A,B,C}, {A,B,E}, {A,C,E}, {B,C,E}

1: {A,B,C,E}
item sets
If support > 0.5

( filter out C )

{A} 3

{B} 3

{A,B} 3

{E} 2

{A,E} 2

{B,E} 2

{A,B,E} 2
frequent item sets
Agrawal, Rakesh; and Srikant, Ramakrishnan; Fast algorithms for mining association rules in large databases, in Bocca,
Jorge B.; Jarke, Matthias; and Zaniolo, Carlo; editors, Proceedings of the 20th International Conference on Very Large
Data Bases (VLDB), Santiago, Chile, September 1994, pages 487-499
FP-Growth Algorithm
• 原理理跟 Apriori ⼀一樣,但利利⽤用 FP-tree 加速搜尋。
[ A, B, E ]

[ A, B, C, E ]

[ A, B ]
transactions FP-tree
ϕ
A
B
E C
E
1
1
1 1
1
2
2
3
3
prefix path
E {A,B}, {A,B,C}
B {A}
A { }
ϕ
conditional tree
on E, ϕ
A
B
{E} 2

{A,E} 2

{B,E} 2

{A,B,E} 2
header table
A 3
B 3
C 1
E 2
on B, {B} 3

{A,B} 3
ϕ
A
{A} 3
on A,
Han (2000). "Mining Frequent Patterns Without Candidate Generation". Proceedings of the 2000 ACM SIGMOD
International Conference on Management of Data. SIGMOD '00: 1–12.
packages
• Python

• Apriori

• FP-growth

• R

• Apriori

https://cran.r-project.org/web/packages/arules/arules.pdf

• FP-growth

https://cran.r-project.org/web/packages/rCBA/rCBA.pdf
from mlxtend.frequent_patterns import apriori
from orangecontrib.associate import fpgrowth
Association Rules on
Distributed Computing
(on Spark)
DataFrame-based API

Since Spark 2.2.0 (July 2017)
https://spark.apache.org/docs/2.2.0/ml-guide.html
Spark 2.1.3 Spark 2.2.0
https://spark.apache.org/docs/2.2.0/ml-frequent-pattern-mining.html
https://spark.apache.org/docs/2.2.0/ml-frequent-pattern-mining.html
https://spark.apache.org/news/index.html
Frequent Pattern
Mining
DataFrames

/ML
(2018-08-31) https://en.wikipedia.org/wiki/Apache_Spark
PySpark
SparkR
Data
Science
spark.ml
DataFrames RDD-based API
Primary API
DateFrame-based

API
Frequent Pattern
Mining
DataFrames

/ML
PySpark
SparkR
Data
Science
spark.ml
DataFrames RDD-based API
Primary API
DateFrame-based

API
(2018-08-31) https://en.wikipedia.org/wiki/Apache_Spark
spark milestones
data process
s3 / HDFS
Spark / Hive
Algorithm

(pure python)
output
PySpark
+
Spark MLlib
output
Scale problems:

1. toPandas( )

2. Limitations of algorithm
GOAL !!!
Demo code
旅遊關聯聯分析
- 以 Osaka Report 為例例
Trata DMP Recap
• Location Data from SDK

• Geography Information System (GIS) from Google API

• Home Country Tags & Cross-Border Travelers -> passport holders

• Reports

• Asia Report since 2016

• Collaboration with GFK - Great China Travelers in Japan

• 台北市觀傳局、⾼高雄市觀傳局

• O2O in ITF

• Osaka Report for Workshop@Osaka

• … etc.
⼤大阪市
京都市
有天...來來⾃自 Marketing 的需求...
Gil~ 有辦法從知道...旅客到

⼤大阪後的旅遊路路徑或⾏行行程嗎?
[路路徑的定義]

裝置有發 Request 才有位置資訊,
有些軌跡很連續、有些很離散,難

以客觀定義路路徑。
[呈現與統計]
很難⽤用視覺化⽅方式同時呈現多⼈人的

移動軌跡。也不易易針對路路徑做任何

的 summary 或統計。
我覺得不⾏行行。
Shiny Spark, Gil 2017/11/24
關⻄西⾏行行程
( )
( )
association rules results
除了了京(京都) 阪(⼤大阪) 神(神⼾戶) ...
奈良
和歌⼭山
+ %
⾏行行程 (購物籃) 中包含:
1. ⼤大阪+京都 ➡ 23.8%
2. ⼤大阪+神⼾戶 ➡ 11.9%
5. ⼤大阪+京都+神⼾戶➡ 5.5%
⼤大阪
京都
兵庫(神⼾戶)
競價關聯聯分析
- 以 Fantasy Basketball 遊戲為例例
Fantasy Basketball
• 線上遊戲:虛擬總經理理 / 總教練

• 非動作類,純數字競賽、管理理遊戲

• ⼀一年年⼀一次,為期約六個⽉月,跟真實 NBA 世界同步

• 季前選秀、季中對戰、季末調整

• 了了解更更多:

• https://www.slideshare.net/wqchen/nba-moneyball-in-web-
application-using-r-20160307-mldm-59782958

• http://www.fansboard.com/
Gil 2016/3/7
球隊陣容(⾃自⼰己組球隊)
對戰實況
季中競標 -12 個玩家(隊)、每隊 13 位球員為例例
• 12 x 13 = 156 位球員,在開季前選秀被選
走,其餘球員則為⾃自由球員 (Free Agent,
FA),FA 可在球季中任何時間被玩家替換。

• 每撿⼀一個 FA,就要丟出隊中⼀一名球員,以
維持各隊 13 ⼈人編制。

• 被丟棄的球員,在三天內,則處於讓渡
(waiver) 狀狀態,⽽而非 FA。三天過後,沒有任
何玩家競標,則成為 FA。

• 被丟棄的球員在 waiver 狀狀態下,如有其他
玩家想要搶先收下該球員,則在三天內,需
要投標,且為⼀一次性暗標,與其他玩家競
標。
全 NBA 每⼀一季⼤大約有 600 位球員
FA
156 picked
players
example
有⼀一天阿岳覺得 J.R. Smith 不⾏行行,於是把 J.R. 丟棄 ...
… 於是,亦凡可以收下 J.R.,

熱狗則飲恨差⼀一點拿到,

瑋柏則拍拍屁股沒事。
$ 18
$ 20 $ 5
這時,有三位玩家對 J.R. 有興趣,於是在 waiver 

期間三天內,各⾃自投下預期的⾦金金額,來來競標 J.R.。
$ 20 $ 18 $ 5
Data -
競價歷史紀錄
association rules results
take away
• DataFrames 版本的分散式運算的實現

• 關聯聯規則分析,⼜又叫購物籃分析,但不是只有購物相關的
數據可以玩,換個⾓角度,都可以找關聯聯規則。
Thank you for your listening ~

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Association Rules Analysis on Spark (20180831 RD sharing)