SlideShare a Scribd company logo
1 of 23
布丁布丁吃布丁
http://blog.pulipuli.info/
2017/1/14
循序樣式探勘:
以R的arulesSequences實作
2
循序樣式探勘介紹
曾憲雄(2005)。資料探勘。
臺北市:旗標。
(ISBN:978-957-442-236-4)
3
循序樣式探勘
●循序樣式探勘的目的是找出顧客在不同時間點所購買的
物品先後之關係。
●例如:
○根據消費者每次交易所購買的產品資料與交易時間,
發掘出類似下列的循序樣式:「80%的顧客如果購買
PC主機和螢幕,則下一次會購買印表機」
○根據學習者在學習活動中不同時間順序,發掘出類似
以下的循序樣式:「50%學習者在回答問題之後瀏覽
討論區」
定義:序列、項目集
●一個序列 (sequence) 是項目集 (itemsets)的有序串列
(ordered list)
○序列 S 被表示成 <s1,s2,…,sn>,其中si (1< i ≦ n) 是項
目集。
○例如,<{10, 20},{30},{90}> 是一個序列,
其中{10, 20}、{30} 以及 {90} 皆是項目集。™
○{10,20}項目集中包含了{10}跟{20}這兩個項目集
4
定義:包含、子序列
●包含:序列 <{a1},{a2},…,{an}> 被包含在序列
<{b1},{b2},…,{bm}> 中,假如存在整數 i1<i2< …<in
滿足
○序列 <{10},{90}>被包含在 <{10, 20},{30},{90}>中
○<{10},{90}>不被包含在 <{10, 90}>。
這是因為在序列 <{10},{90}> 中,項目集 {10} 和 {90}
是先後在不同交易中被購買的。
●若序列S包含序列S’,
則稱序列S’為序列S的 「子序列」 (subsequence)。
5
定義:k-序列、最大序列
●一個包含 k個項目集的序列稱之為k-序列 (k-sequence)
●給定一組序列S,若序列S不被包含在其它序列中,
則稱它為 「最大序列」 (maximal sequence)。
○每一個最大序列則代表一個
循序樣式 (sequential pattern)。
○例如兩個序列:
2序列:<{10},{90}>
3序列:<{10, 20},{30},{90}>
3序列不被包含在其他序列中,它就是最大序列
6
定義:顧客序列
●對於每一個顧客,將他所有的交易根據交易時間排序所
得到的結果就是一個「顧客序列」。
7
會員帳號 顧客序列
1 <{10,20},{30},{40,60}>
2 <{10,20},{30},{90}>
3 <{30},{90}>
4 <{10,20,30}>
5 <{30},{60,90}>
定義:支持度、最小支持度
●一個序列 S的「支持度 (support)」被定義為「包含S的
顧客序列之總數佔全部顧客總數的比例」。
○有多少比例的顧客都會做這樣的序列
●若序列滿足使用者設定的「最小支持度」 (minimum
Support) 之限制,則稱之為 「大型序列」 (large
Sequence)。
○一旦發掘所有的大型序列之後,就能夠輕易產生所有
的最大序列。
○循序樣式探勘的問題就是要找出所有的循序樣式,也
就是所有的最大序列。
8
範例:依會員帳號和交易時間
排序後的資料庫
9
範例:顧客序列資料庫
10
會員帳號 顧客序列
1 <{10,20},{30},{40,60}>
2 <{10,20},{30},{90}>
3 <{30},{90}>
4 <{10,20,30}>
5 <{30},{60,90}>
範例試算
●設定最小支持度為0.2:因為會
員帳號總數為5,所以最小支持
個數需大於5*0.2=1。
●序列 <{30}> 和 <{30},{90}>
的支持個數分別為5和3,支持
度為1跟0.6,所以它們都是大
型序列。
●結果:最大序列為<{30},{90}>
○序列 <{30}>不是最大序列,
因為它被包含在大型序列
<{30},{90}> 之中。
11
會員
帳號
顧客序列
1 <{10,20},{30},{40,60}>
2 <{10,20},{30},{90}>
3 <{30},{90}>
4 <{10,20,30}>
5 <{30},{60,90}>
12
以R實作arulesSequences
Data Mining Algorithms In R
/Sequence Mining/SPADE
https://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Sequence_Mining/SPADE
13
資料集與運作環境
●運作環境
RStudio
●資料集
input.csv
●執行腳本
arulesSequences.r
操作步驟
1.配置腳本與資料
2.準備資料集
3.從R腳本開啟RStudio
4.設定最小支持度
5.全選腳本與執行
6.輸出結果
7.解釋結果
14
1. 配置腳本與資料
15
2. 準備資料集
input.csv
16
1 2 3
1.使用者代號
2.時間
3.事件
(用空白區隔)
3. 從R腳本開啟RStudio
17
預設最小支持度0.4=找出40%以上的人共有的循序樣式
4. 設定最小支持度
18
5. 全選腳本與執行
19
全選
(Ctrl+a)
執行
(Ctrl+Enter)
6. 輸出結果
20
7. 解釋結果
21
score sequence
_length
support sequence score sequence
_length
support sequence
1.5 3 0.5 <{P},{F},{A}> 1 2 0.5 <{P},{B}>
1.5 3 0.5 <{P},{B},{A}> 1 2 0.5 <{B},{A}>
1.5 3 0.5 <{P},{B,F},{A}> 1 2 0.5 <{F},{A}>
1 1 1 <{A}> 1 2 0.5 <{P},{A}>
1 1 1 <{B}> 1 2 0.5 <{B,F},{A}>
1 1 1 <{F}> 0.75 1 0.75 <{A,F}>
1 1 1 <{B,F}> 0.75 1 0.75 <{A,B,F}>
1 2 0.5 <{P},{F}> 0.75 1 0.75 <{A,B}>
1 2 0.5 <{P},{B,F}> 0.5 1 0.5 <{P}>
score 最大&支持度高
=sequence_length*support
7. 解釋結果
22
score sequence
_length
support sequence score sequence
_length
support sequence
1.5 3 0.5 <{P},{F},{A}> 1 2 0.5 <{P},{B}>
1.5 3 0.5 <{P},{B},{A}> 1 2 0.5 <{B},{A}>
1.5 3 0.5 <{P},{B,F},{A}> 1 2 0.5 <{F},{A}>
1 1 1 <{A}> 1 2 0.5 <{P},{A}>
1 1 1 <{B}> 1 2 0.5 <{B,F},{A}>
1 1 1 <{F}> 0.75 1 0.75 <{A,F}>
1 1 1 <{B,F}> 0.75 1 0.75 <{A,B,F}>
1 2 0.5 <{P},{F}> 0.75 1 0.75 <{A,B}>
1 2 0.5 <{P},{B,F}> 0.5 1 0.5 <{P}>
1 10 2 C P
1 15 3 A B C
1 20 3 A B F
1 25 4 A C P F
2 15 3 A B F
2 20 1 E
3 10 3 A B F
4 10 3 P G H
4 20 2 B F
4 25 3 A G H
BLOG: 布丁布丁吃什麼?
http://blog.pulipuli.info/
23

More Related Content

More from Yung-Ting Chen

2. 看穿因果:熱點分析 - 2021.pptx
2. 看穿因果:熱點分析 - 2021.pptx2. 看穿因果:熱點分析 - 2021.pptx
2. 看穿因果:熱點分析 - 2021.pptxYung-Ting Chen
 
1. 神鳥領航:初識Weka - 2021.pptx
1. 神鳥領航:初識Weka - 2021.pptx1. 神鳥領航:初識Weka - 2021.pptx
1. 神鳥領航:初識Weka - 2021.pptxYung-Ting Chen
 
論文神器+ChatGPT - blog - 2023.pptx
論文神器+ChatGPT - blog - 2023.pptx論文神器+ChatGPT - blog - 2023.pptx
論文神器+ChatGPT - blog - 2023.pptxYung-Ting Chen
 
大數據時代下的文本分析 - 22 dils text.pptx
大數據時代下的文本分析 - 22 dils text.pptx大數據時代下的文本分析 - 22 dils text.pptx
大數據時代下的文本分析 - 22 dils text.pptxYung-Ting Chen
 
人工智慧的可解釋性 - blog - 2023.pptx
人工智慧的可解釋性 - blog - 2023.pptx人工智慧的可解釋性 - blog - 2023.pptx
人工智慧的可解釋性 - blog - 2023.pptxYung-Ting Chen
 
Introduction to TextRank - 22.pptx
Introduction to TextRank - 22.pptxIntroduction to TextRank - 22.pptx
Introduction to TextRank - 22.pptxYung-Ting Chen
 
Subgroup-Discovery-2021.pptx
Subgroup-Discovery-2021.pptxSubgroup-Discovery-2021.pptx
Subgroup-Discovery-2021.pptxYung-Ting Chen
 
1. introduction of weka
1. introduction of weka1. introduction of weka
1. introduction of wekaYung-Ting Chen
 
3. classification and regression
3. classification and regression3. classification and regression
3. classification and regressionYung-Ting Chen
 
2. clustering and association rule mining
2. clustering and association rule mining2. clustering and association rule mining
2. clustering and association rule miningYung-Ting Chen
 
Word專業文件排版:第8堂面授 (20151223) blog
Word專業文件排版:第8堂面授 (20151223) blogWord專業文件排版:第8堂面授 (20151223) blog
Word專業文件排版:第8堂面授 (20151223) blogYung-Ting Chen
 
Word專業文件排版:第6堂面授 (20151202) blog
Word專業文件排版:第6堂面授 (20151202) blogWord專業文件排版:第6堂面授 (20151202) blog
Word專業文件排版:第6堂面授 (20151202) blogYung-Ting Chen
 
Word專業文件排版:第3堂面授 (20151014) blog
Word專業文件排版:第3堂面授 (20151014) blogWord專業文件排版:第3堂面授 (20151014) blog
Word專業文件排版:第3堂面授 (20151014) blogYung-Ting Chen
 
Word專業文件排版:第2堂面授 (20150923) blog
Word專業文件排版:第2堂面授 (20150923) blogWord專業文件排版:第2堂面授 (20150923) blog
Word專業文件排版:第2堂面授 (20150923) blogYung-Ting Chen
 
Apache solr教學介紹 20150501
Apache solr教學介紹 20150501Apache solr教學介紹 20150501
Apache solr教學介紹 20150501Yung-Ting Chen
 
20161110 行為分析之對數線性模式 blog
20161110 行為分析之對數線性模式 blog20161110 行為分析之對數線性模式 blog
20161110 行為分析之對數線性模式 blogYung-Ting Chen
 
20161027 行為分析之時間序列分析 public
20161027 行為分析之時間序列分析   public20161027 行為分析之時間序列分析   public
20161027 行為分析之時間序列分析 publicYung-Ting Chen
 

More from Yung-Ting Chen (20)

2. 看穿因果:熱點分析 - 2021.pptx
2. 看穿因果:熱點分析 - 2021.pptx2. 看穿因果:熱點分析 - 2021.pptx
2. 看穿因果:熱點分析 - 2021.pptx
 
1. 神鳥領航:初識Weka - 2021.pptx
1. 神鳥領航:初識Weka - 2021.pptx1. 神鳥領航:初識Weka - 2021.pptx
1. 神鳥領航:初識Weka - 2021.pptx
 
論文神器+ChatGPT - blog - 2023.pptx
論文神器+ChatGPT - blog - 2023.pptx論文神器+ChatGPT - blog - 2023.pptx
論文神器+ChatGPT - blog - 2023.pptx
 
大數據時代下的文本分析 - 22 dils text.pptx
大數據時代下的文本分析 - 22 dils text.pptx大數據時代下的文本分析 - 22 dils text.pptx
大數據時代下的文本分析 - 22 dils text.pptx
 
人工智慧的可解釋性 - blog - 2023.pptx
人工智慧的可解釋性 - blog - 2023.pptx人工智慧的可解釋性 - blog - 2023.pptx
人工智慧的可解釋性 - blog - 2023.pptx
 
Introduction to TextRank - 22.pptx
Introduction to TextRank - 22.pptxIntroduction to TextRank - 22.pptx
Introduction to TextRank - 22.pptx
 
Subgroup-Discovery-2021.pptx
Subgroup-Discovery-2021.pptxSubgroup-Discovery-2021.pptx
Subgroup-Discovery-2021.pptx
 
1. introduction of weka
1. introduction of weka1. introduction of weka
1. introduction of weka
 
4. applications
4. applications4. applications
4. applications
 
3. classification and regression
3. classification and regression3. classification and regression
3. classification and regression
 
2. clustering and association rule mining
2. clustering and association rule mining2. clustering and association rule mining
2. clustering and association rule mining
 
20180518 pbl
20180518 pbl20180518 pbl
20180518 pbl
 
20180518 kals
20180518 kals20180518 kals
20180518 kals
 
Word專業文件排版:第8堂面授 (20151223) blog
Word專業文件排版:第8堂面授 (20151223) blogWord專業文件排版:第8堂面授 (20151223) blog
Word專業文件排版:第8堂面授 (20151223) blog
 
Word專業文件排版:第6堂面授 (20151202) blog
Word專業文件排版:第6堂面授 (20151202) blogWord專業文件排版:第6堂面授 (20151202) blog
Word專業文件排版:第6堂面授 (20151202) blog
 
Word專業文件排版:第3堂面授 (20151014) blog
Word專業文件排版:第3堂面授 (20151014) blogWord專業文件排版:第3堂面授 (20151014) blog
Word專業文件排版:第3堂面授 (20151014) blog
 
Word專業文件排版:第2堂面授 (20150923) blog
Word專業文件排版:第2堂面授 (20150923) blogWord專業文件排版:第2堂面授 (20150923) blog
Word專業文件排版:第2堂面授 (20150923) blog
 
Apache solr教學介紹 20150501
Apache solr教學介紹 20150501Apache solr教學介紹 20150501
Apache solr教學介紹 20150501
 
20161110 行為分析之對數線性模式 blog
20161110 行為分析之對數線性模式 blog20161110 行為分析之對數線性模式 blog
20161110 行為分析之對數線性模式 blog
 
20161027 行為分析之時間序列分析 public
20161027 行為分析之時間序列分析   public20161027 行為分析之時間序列分析   public
20161027 行為分析之時間序列分析 public
 

20170114 循序樣式探勘:以r實作