序列模式PrefixSpan演算法介紹

來源:互聯網
上載者:User

序列

序列(sequence)是一組排好序的項集,不一定是直接連續的,但依然滿足次序。序列模式的元素還可以是一個項集,如一組頁面序列。序列模式挖掘比關聯挖掘能得到更深刻的知識。

序列模式

sequence patternmining,針對Frequent Sequences,典型的應用還是限於離散型的序列,happens-after relationship and not just the consecutive subsequences。

可用於購買行為預測、欺詐甄別、故障預測、Web使用者訪問預測、人類行為規律等。

演算法是各種類APRIORI演算法,有AprioriAll、AprioriSome、GSP (Generalized Sequential Patterns)、SPADE(Sequential PAttern Discovery using Equivalence classes)、PrefixSpan。



與時間序列的區別

與time series mining時間序列不同,時間序列(或稱動態數列)是指將同一統計指標的數值按其發生的時間先後順序排列而成的數列。時間序列分析的主要目的是根據已有的曆史資料對未來進行預測。常見MA、AR、ARMA、GARCH模型。


例子

<a(abc)(ac)d(cf)>- 9 items(項), 5 itemsets(項集), 1 sequence(序列)

<a(abc)(ac)d(cf)> = <a(cba)(ac)d(cf)>

<a(abc)(ac)d(cf)> ≠ <a(ac)(abc)d(cf)>

Min support(最小支援度)threshold - 頻繁子序列的頻繁度不低於最小支援度(Find all the frequent subsequences,i.e. the subsequences whose occurrence frequency in the set of sequences is noless than min_support)

Supersequence: <a(abc)(ac)d(cf)>

Sub-sequence:<aa(ac)d(c)>

Sub-sequence:<(ac)(ac)d(cf)>

Sub-sequence:<ac>

 

<a(abc)(ac)d(cf)>  α1=<a> support(α1) = 4

<(ad)c(bc)(ae)>    α2=<ac> support(α2) = 4

<(ef)(ab)(df)cb>   α3=<(ab)c> support(α3) = 2

<eg(af)cbc>


=================

PrefixSpan

首碼prefix

seq <a(abc)a> is a prefix of seq<a(abc)(ac)d(cf)>, but seq <a(abc)c> is NOT. <a>、<aa>、<a(ab)>、<a(abc)>是序列<a(abc)(ac)d(cf)>的首碼,而<ab>、<a(bc)>不是。


尾碼postfix

Seqβ <a(abc)a> is a prefix and seqγ <(_c)d(cf)> is a postfix of seqα<a(abc)(ac)d(cf)>. Denote α =β⋅γ或γ=α/β

對於序列<a(abc)(ac)d(cf)>,

<(abc)(ac)d(cf)>是首碼<a>的尾碼;

<(_bc)(ac)d(cf)>是首碼<aa>的尾碼;

<(_c)(ac)d(cf)>是首碼<a(ab)>的尾碼;

"_"下標符代表首碼。

投影Projection

投影即投影資料庫,是序列資料庫S中所有相對於α首碼的尾碼序列的集合。

演算法

子程式:PrefixSpan(α,l, )

參數:

α指首碼序列模式;

l指α的長度;

指α的投影資料庫。

演算法:

1、  掃描,找出頻繁項集b:
  a)b可以成為α的最後一個項集(如ab + c=> abc),或者:
  b)b可以追加到α形成新一個序列模式(如ab +_c => a(bc));

2、  對於每個頻繁項b,追加到α形成新一個序列模式α’(如abc或a(bc));

3、  對於每個α’,構造α’的投影資料庫,並調用prefixspan(α’, l+1, ) 其過程為深度優先搜尋。


優點:

1)不產生任何的侯選集,減少空間;

2)投影資料庫規模不斷減少(因為投影僅發生在與首碼相關的尾碼部分);

3)採用分而治之的方法,提高了演算法效率,而且與SPADE和GSP演算法相比,在記憶體使用量上更加的穩定;

缺點:

1)演算法主要開銷在於投影資料庫的構造,如果序列多且每個序列建立一個投影資料庫,那麼開銷就比較大(可通過a.偽投影技術(Pseudo-projection)減少投影資料庫的數量和大小;b.Bi-level projection); 2)實現難度較大。


例子



部分示範過程



最終結果



代碼列印結果(可用於調試對照)

MIN_SUPPORT: 2


Input Sequence:a (abc) (ac) d (cf)
Input Sequence: (ad) c (bc) (ae)
Input Sequence: (ef) (ab) (df) c b
Input Sequence: e g (af) c b c
frequence: a=4 b=4 c=4 d=3 e=3 f=3 g=1 
support: a=4 b=4 c=4 d=3 e=3 f=3 
fullPrefix~~~: a
lastPrefix: a, postFix: (abc) (ac) d (cf)
lastPrefix: a, postFix: (_d) c (bc) (ae)
lastPrefix: a, postFix: (_b) (df) c b
lastPrefix: a, postFix: (_f) c b c


Input Sequence:(abc) (ac) d (cf)
Input Sequence:(_d) c (bc) (ae)
Input Sequence:(_b) (df) c b
Input Sequence:(_f) c b c
frequence: a=2 b=4 _b=2 c=4 _c=1 d=2 _d=1 e=1 f=2 _e=1 _f=1 
support: a=2 b=4 _b=2 c=4 d=2 f=2 
fullPrefix~~~: aa
lastPrefix: a, postFix: (_bc) (ac) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_bc) (ac) d (cf)
Input Sequence:(_e)
frequence: a=1 _b=1 c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: ab
lastPrefix: b, postFix: (_c) (ac) d (cf)
lastPrefix: b, postFix: (_c) (ae)
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:(_c) (ac) d (cf)
Input Sequence:(_c) (ae)
Input Sequence:
Input Sequence:c
frequence: a=2 c=2 _c=2 d=1 e=1 f=1 
support: a=2 c=2 _c=2 
fullPrefix~~~: aba
lastPrefix: a, postFix: (_c) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_c) d (cf)
Input Sequence:(_e)
frequence: c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: abc
lastPrefix: c, postFix: d (cf)
lastPrefix: c, postFix: 


Input Sequence:d (cf)
Input Sequence:
frequence: c=1 d=1 f=1 _f=1 
support: 
fullPrefix~~~: a(bc)
lastPrefix: _c, postFix: (ac) d (cf)
lastPrefix: _c, postFix: (ae)


Input Sequence:(ac) d (cf)
Input Sequence:(ae)
frequence: a=2 c=1 d=1 e=1 f=1 
support: a=2 
fullPrefix~~~: a(bc)a
lastPrefix: a, postFix: (_c) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_c) d (cf)
Input Sequence:(_e)
frequence: c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: (ab)
lastPrefix: _b, postFix: (_c) (ac) d (cf)
lastPrefix: _b, postFix: (df) c b


Input Sequence:(_c) (ac) d (cf)
Input Sequence:(df) c b
frequence: a=1 b=1 c=2 _c=1 d=2 f=2 
support: c=2 d=2 f=2 
fullPrefix~~~: (ab)c
lastPrefix: c, postFix: d (cf)
lastPrefix: c, postFix: b


Input Sequence:d (cf)
Input Sequence:b
frequence: b=1 c=1 d=1 f=1 _f=1 
support: 
fullPrefix~~~: (ab)d
lastPrefix: d, postFix: (cf)
lastPrefix: d, postFix: (_f) c b


Input Sequence:(cf)
Input Sequence:(_f) c b
frequence: b=1 c=2 f=1 _f=1 
support: c=2 
fullPrefix~~~: (ab)dc
lastPrefix: c, postFix: (_f)
lastPrefix: c, postFix: b


Input Sequence:(_f)
Input Sequence:b
frequence: b=1 _f=1 
support: 
fullPrefix~~~: (ab)f
lastPrefix: f, postFix: 
lastPrefix: f, postFix: c b


Input Sequence:
Input Sequence:c b
frequence: b=1 c=1 
support: 
fullPrefix~~~: ac
lastPrefix: c, postFix: (ac) d (cf)
lastPrefix: c, postFix: (bc) (ae)
lastPrefix: c, postFix: b
lastPrefix: c, postFix: b c


Input Sequence:(ac) d (cf)
Input Sequence:(bc) (ae)
Input Sequence:b
Input Sequence:b c
frequence: a=2 b=3 c=3 d=1 e=1 f=1 _f=1 
support: a=2 b=3 c=3 
fullPrefix~~~: aca
lastPrefix: a, postFix: (_c) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_c) d (cf)
Input Sequence:(_e)
frequence: c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: acb
lastPrefix: b, postFix: (_c) (ae)
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:(_c) (ae)
Input Sequence:
Input Sequence:c
frequence: a=1 c=1 _c=1 e=1 
support: 
fullPrefix~~~: acc
lastPrefix: c, postFix: d (cf)
lastPrefix: c, postFix: (ae)
lastPrefix: c, postFix: 


Input Sequence:d (cf)
Input Sequence:(ae)
Input Sequence:
frequence: a=1 c=1 d=1 e=1 f=1 _f=1 
support: 
fullPrefix~~~: ad
lastPrefix: d, postFix: (cf)
lastPrefix: d, postFix: (_f) c b


Input Sequence:(cf)
Input Sequence:(_f) c b
frequence: b=1 c=2 f=1 _f=1 
support: c=2 
fullPrefix~~~: adc
lastPrefix: c, postFix: (_f)
lastPrefix: c, postFix: b


Input Sequence:(_f)
Input Sequence:b
frequence: b=1 _f=1 
support: 
fullPrefix~~~: af
lastPrefix: f, postFix: 
lastPrefix: f, postFix: c b


Input Sequence:
Input Sequence:c b
frequence: b=1 c=1 
support: 
fullPrefix~~~: b
lastPrefix: b, postFix: (_c) (ac) d (cf)
lastPrefix: b, postFix: (_c) (ae)
lastPrefix: b, postFix: (df) c b
lastPrefix: b, postFix: c


Input Sequence:(_c) (ac) d (cf)
Input Sequence:(_c) (ae)
Input Sequence:(df) c b
Input Sequence:c
frequence: a=2 b=1 c=3 _c=2 d=2 e=1 f=2 
support: a=2 c=3 _c=2 d=2 f=2 
fullPrefix~~~: ba
lastPrefix: a, postFix: (_c) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_c) d (cf)
Input Sequence:(_e)
frequence: c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: bc
lastPrefix: c, postFix: d (cf)
lastPrefix: c, postFix: b
lastPrefix: c, postFix: 


Input Sequence:d (cf)
Input Sequence:b
Input Sequence:
frequence: b=1 c=1 d=1 f=1 _f=1 
support: 
fullPrefix~~~: (bc)
lastPrefix: _c, postFix: (ac) d (cf)
lastPrefix: _c, postFix: (ae)


Input Sequence:(ac) d (cf)
Input Sequence:(ae)
frequence: a=2 c=1 d=1 e=1 f=1 
support: a=2 
fullPrefix~~~: (bc)a
lastPrefix: a, postFix: (_c) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_c) d (cf)
Input Sequence:(_e)
frequence: c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: bd
lastPrefix: d, postFix: (cf)
lastPrefix: d, postFix: (_f) c b


Input Sequence:(cf)
Input Sequence:(_f) c b
frequence: b=1 c=2 f=1 _f=1 
support: c=2 
fullPrefix~~~: bdc
lastPrefix: c, postFix: (_f)
lastPrefix: c, postFix: b


Input Sequence:(_f)
Input Sequence:b
frequence: b=1 _f=1 
support: 
fullPrefix~~~: bf
lastPrefix: f, postFix: 
lastPrefix: f, postFix: c b


Input Sequence:
Input Sequence:c b
frequence: b=1 c=1 
support: 
fullPrefix~~~: c
lastPrefix: c, postFix: (ac) d (cf)
lastPrefix: c, postFix: (bc) (ae)
lastPrefix: c, postFix: b
lastPrefix: c, postFix: b c


Input Sequence:(ac) d (cf)
Input Sequence:(bc) (ae)
Input Sequence:b
Input Sequence:b c
frequence: a=2 b=3 c=3 d=1 e=1 f=1 _f=1 
support: a=2 b=3 c=3 
fullPrefix~~~: ca
lastPrefix: a, postFix: (_c) d (cf)
lastPrefix: a, postFix: (_e)


Input Sequence:(_c) d (cf)
Input Sequence:(_e)
frequence: c=1 _c=1 d=1 f=1 _e=1 
support: 
fullPrefix~~~: cb
lastPrefix: b, postFix: (_c) (ae)
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:(_c) (ae)
Input Sequence:
Input Sequence:c
frequence: a=1 c=1 _c=1 e=1 
support: 
fullPrefix~~~: cc
lastPrefix: c, postFix: d (cf)
lastPrefix: c, postFix: (ae)
lastPrefix: c, postFix: 


Input Sequence:d (cf)
Input Sequence:(ae)
Input Sequence:
frequence: a=1 c=1 d=1 e=1 f=1 _f=1 
support: 
fullPrefix~~~: d
lastPrefix: d, postFix: (cf)
lastPrefix: d, postFix: c (bc) (ae)
lastPrefix: d, postFix: (_f) c b


Input Sequence:(cf)
Input Sequence:c (bc) (ae)
Input Sequence:(_f) c b
frequence: a=1 b=2 c=3 e=1 f=1 _f=1 
support: b=2 c=3 
fullPrefix~~~: db
lastPrefix: b, postFix: (_c) (ae)
lastPrefix: b, postFix: 


Input Sequence:(_c) (ae)
Input Sequence:
frequence: a=1 _c=1 e=1 
support: 
fullPrefix~~~: dc
lastPrefix: c, postFix: (_f)
lastPrefix: c, postFix: (bc) (ae)
lastPrefix: c, postFix: b


Input Sequence:(_f)
Input Sequence:(bc) (ae)
Input Sequence:b
frequence: a=1 b=2 c=1 e=1 _f=1 
support: b=2 
fullPrefix~~~: dcb
lastPrefix: b, postFix: (_c) (ae)
lastPrefix: b, postFix: 


Input Sequence:(_c) (ae)
Input Sequence:
frequence: a=1 _c=1 e=1 
support: 
fullPrefix~~~: e
lastPrefix: e, postFix: 
lastPrefix: e, postFix: (_f) (ab) (df) c b
lastPrefix: e, postFix: g (af) c b c


Input Sequence:
Input Sequence:(_f) (ab) (df) c b
Input Sequence:g (af) c b c
frequence: a=2 b=2 c=2 d=1 f=2 _f=1 g=1 
support: a=2 b=2 c=2 f=2 
fullPrefix~~~: ea
lastPrefix: a, postFix: (_b) (df) c b
lastPrefix: a, postFix: (_f) c b c


Input Sequence:(_b) (df) c b
Input Sequence:(_f) c b c
frequence: b=2 _b=1 c=2 d=1 f=1 _f=1 
support: b=2 c=2 
fullPrefix~~~: eab
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:
Input Sequence:c
frequence: c=1 
support: 
fullPrefix~~~: eac
lastPrefix: c, postFix: b
lastPrefix: c, postFix: b c


Input Sequence:b
Input Sequence:b c
frequence: b=2 c=1 
support: b=2 
fullPrefix~~~: eacb
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:
Input Sequence:c
frequence: c=1 
support: 
fullPrefix~~~: eb
lastPrefix: b, postFix: (df) c b
lastPrefix: b, postFix: c


Input Sequence:(df) c b
Input Sequence:c
frequence: b=1 c=2 d=1 f=1 
support: c=2 
fullPrefix~~~: ebc
lastPrefix: c, postFix: b
lastPrefix: c, postFix: 


Input Sequence:b
Input Sequence:
frequence: b=1 
support: 
fullPrefix~~~: ec
lastPrefix: c, postFix: b
lastPrefix: c, postFix: b c


Input Sequence:b
Input Sequence:b c
frequence: b=2 c=1 
support: b=2 
fullPrefix~~~: ecb
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:
Input Sequence:c
frequence: c=1 
support: 
fullPrefix~~~: ef
lastPrefix: f, postFix: c b
lastPrefix: f, postFix: c b c


Input Sequence:c b
Input Sequence:c b c
frequence: b=2 c=2 
support: b=2 c=2 
fullPrefix~~~: efb
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:
Input Sequence:c
frequence: c=1 
support: 
fullPrefix~~~: efc
lastPrefix: c, postFix: b
lastPrefix: c, postFix: b c


Input Sequence:b
Input Sequence:b c
frequence: b=2 c=1 
support: b=2 
fullPrefix~~~: efcb
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:
Input Sequence:c
frequence: c=1 
support: 
fullPrefix~~~: f
lastPrefix: f, postFix: 
lastPrefix: f, postFix: (ab) (df) c b
lastPrefix: f, postFix: c b c


Input Sequence:
Input Sequence:(ab) (df) c b
Input Sequence:c b c
frequence: a=1 b=2 c=2 d=1 f=1 
support: b=2 c=2 
fullPrefix~~~: fb
lastPrefix: b, postFix: (df) c b
lastPrefix: b, postFix: c


Input Sequence:(df) c b
Input Sequence:c
frequence: b=1 c=2 d=1 f=1 
support: c=2 
fullPrefix~~~: fbc
lastPrefix: c, postFix: b
lastPrefix: c, postFix: 


Input Sequence:b
Input Sequence:
frequence: b=1 
support: 
fullPrefix~~~: fc
lastPrefix: c, postFix: b
lastPrefix: c, postFix: b c


Input Sequence:b
Input Sequence:b c
frequence: b=2 c=1 
support: b=2 
fullPrefix~~~: fcb
lastPrefix: b, postFix: 
lastPrefix: b, postFix: c


Input Sequence:
Input Sequence:c
frequence: c=1 
support: 
fullPrefixDb:
a, aa, ab, aba, abc, a(bc), a(bc)a, (ab), (ab)c, (ab)d, (ab)dc, (ab)f, ac, aca, acb, acc, ad, adc, af, b, ba, bc, (bc), (bc)a, bd, bdc, bf, c, ca, cb, cc, d, db, dc, dcb, e, ea, eab, eac, eacb, eb, ebc, ec, ecb, ef, efb, efc, efcb, f, fb, fbc, fc, fcb, 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.