380 likes | 738 Views
相関ルールを求める. 目次. 相関ルール Apriori algorithm 頻出アイテム集合を探す subset 関数 Apriori-Gen 関数 相関ルールを探す FP-growth algorithm さまざまな手法. 相関ルールとは. 「目玉商品 A と日用品 B を購入した顧客は、同時に高級品 C も高い確率で購入する」. A,B,C のセット商品を発売する 顧客の便利性を考えて、商品の配置を近づける. { 目玉商品 A 、日用品 B}⇒{ 高級品 C} と表現できる. {X}⇒{Y}. 定義. 価値のある相関ルールを求める.
E N D
目次 • 相関ルール • Apriori algorithm • 頻出アイテム集合を探す • subset関数 • Apriori-Gen関数 • 相関ルールを探す • FP-growth algorithm • さまざまな手法
相関ルールとは 「目玉商品Aと日用品Bを購入した顧客は、同時に高級品Cも高い確率で購入する」 • A,B,Cのセット商品を発売する • 顧客の便利性を考えて、商品の配置を近づける {目玉商品A、日用品B}⇒{高級品C}と表現できる {X}⇒{Y}
価値のある相関ルールを求める • Mこのアイテムの中からkこを選ぶ方法= • kこのアイテムの各々が前提に来るか、結論に来るかのわけ方= 2k • 全部のアイテムが前提に集まる場合と、結論に集まる場合は、ルールにならないので排除 • 2k -2
価値のある相関ルールを求める • アイテムが10種類の場合でもルールは約57,000もある • 価値のある相関ルールはわずかだけ • 価値のある相関ルールとは • 確信度が高い • 支持率が高い
アプリオリアルゴリズム(Agrawal 1994, VLDB94) • 最小確信度、最小サポートを与えて確信度、サポートがそれ以上の相関ルールを発見する support(XUY)>α support(XUY)/support(X)>β を満たす相関ルールX⇒Yを取り出すのが目的
アイテム集合のサポートは単調減であることを使う。アイテム集合のサポートは単調減であることを使う。 この背反を取ると support(XUY)とsupport(X)が必要。 support(XUY)は最小サポート以上であるので、XUYの部分集合であるXのサポートも最小サポート以上 最小サポート以上の頻出アイテム集合のサポートを求めておけばすべての相関ルールの確信度を求めることができる 効率よく探し出すために {A,B}が頻出アイテム集合でない ↓ {A,B,C}も頻出アイテム集合ではない {A,B,C}が頻出アイテム集合⇒{A,B}も頻出アイテム集合
アルゴリズム • support(XUY)>αを満たす頻出アイテム集合をすべて探し出し、サポートを求める • support(XUY)/support(X)>β を満たす相関ルールを探し出す (1)が求まれば、それを使うと(2)は簡単 どうやって(1)を効率よくもとめるか
頻出アイテム集合を探し出す • 要素数の少ないサポートから求めていき、最小サポートより少ない集合を含めるものは計算しない {A,B}が頻出アイテム集合でない⇒ {A,B,C}も頻出アイテム集合ではない • データベースをスキャンしCk中の各サポートを計算する • Ck中の最小サポートを満足する部分をLkとする • LkからCk+1を生成する
Apriori algorithm L1={large item set} for ( k=2; Lk-1β≠Ø; k++) do { Ck= apriori_gen(Lk-1) ; // New candidates for (all transactions t in D )do { Ct = subset(Ck , t) // Candidates contained in t; for (all candidates c in Ct) do {c.count++} }; Lk ={c in Ck | c.count≥ minsup} } Answer ∪k Lk }
頻出アイテム集合の候補 頻出アイテム集合 subset関数 Apriori-Gen関数
Apriori-Gen関数 • 結合フェーズ • Lk中から最後の要素だけが異なる二つのアイテム集合を結合して要素数k+1の候補アイテム集合を作る • 枝狩りフェーズ • 結合フェーズで作った候補アイテム集合に対し、要素数kの部分集合がLkに含まれていないような候補を除去する
頻出アイテム集合C3 頻出アイテム集合の候補L4 要素数3の部分集合 {A,D,E} が含まれていないので、 {A,C,D,E}は排除
Apriori_Gen insert into Ck select p.item1,….,p.itemk-1, q.itemk from Lk-1 p, Lk-1 q where p.item1=q.item1,…,p.itemk-1=q.itemk-1, p.itemk ≠ q.itemk //prune for (all itemsets c in Ck )do for(all k-1 subsets s of c )do {if s not in Lk-1 then delete c from Ck} } }
subset関数 • トランザクションtに含まれる候補アイテム集合を見つけ出す • 例 • t={A,B,C,E} • 候補アイテム集合C2 から{A,B}1、{A,C}2、 {A,E}1、 {B,C}2、 {B,E}3、 {C,E}2 (数字は出現回数) • SUBSET(C2,t)={{A,C}、 {B,C}、 {B,E}、{C,E}}
t={A,B,C,E} root B A C {C,E} {E} {B,C,E} C E B C E E {C,E} C E 候補アイテム集合{A,B}、{A,C}、{A,E}、{B,C}、{B,E}、{C,E}
相関ルールの導出 対偶をとる • {A,B,C}⇒{D}と{A,B,D}⇒{C}のどちらか一方でも最小確信度未満ならば • {A,B}⇒{C,D}も最小確信度未満である
頻出アイテム集合{A,B,C,D}について考える ??頻出アイテム集合{A,B,C,D}について考える ?? なし
FP-growth algorithm • Apriori algorithm の効率を大きく改善するアルゴリズム(J.Han, 1999 SIGMOD)
I = {a1; a2; : : :; am} be a set of items • a transaction database DB = {T1; T2; : :Tn} • where Ti (i =1,..,n) is a transaction which contains a set of items in I. • The support1 (or occurrence frequency) of a pattern A, which is a set of items is the number of transactions containing A in DB. • A is a frequent pattern if A's support is no less than a predefined minimum support threshold, ξ.
FP-treeの定義 • 要素 • one root “null” • a set ofitem prefix subtrees as the children of the root • a frequent-item header table • Node in the item prefix subtree consists of • (1)item-name, (2)count, (3)node-link • frequent-item header table con-sists of • (1) item-name and (2) head of node-link
例 Item name Count Item link a:3----->
FP-tree construction algorithm Step1:DBをscanし、ξ以上の頻度を持つfrequent item Fを集め、頻度の降順にソート。 Step2:DBの格要素(transaction)において、それに含まれるitemを頻度の降順にソートし、 Step3: for( each transaction: L) do { root のnullノードからスタートして、以下のように rootにぶら下がる木を作る。ただし、T=rootする; L=[p|P], pは先頭の要素、Pは残りのリスト; insert_tree([p|P],T) }
insert_tree([p|P],T) { If T has a child N such that N.item-name= p.item-name, then increment N's count by 1; else { create a new node N, and let its count be 1; its parent link be linked to T; its node-linkbe linked to the nodes with the same item-namevia the node-link structure. } If P is nonempty, then call insert tree(P;N) recursively }
FP-Treeの木の高さは、ひとつのtransactionに含まれるitemの個数の最大値FP-Treeの木の高さは、ひとつのtransactionに含まれるitemの個数の最大値 • Rootからleafまでの枝(path)において、itemは頻度の降順に並んでいる。
Property 3.1 (Node-link property) For any frequent item ai, all the possible frequent patterns that contain ai can be obtained by following ai's node-links,starting from ai's head in the FP-tree header.
パタンマイニング関数:mine • Header table の中で、一番頻度の低い(つまり、一番下の) itemから順にパターンを探す。 • (p:3)の上に来るパタンはpの条件付パタンベースと呼ばれ、以下の通り。 • {<f:4; c:3; a:3;m:2>|p}, {<c:1; b:1>|p} • pの上に共通に来るパタンはcのみなので、抽出されたパタンは (cp:3)だけ。
つづき • mの上には、<f:4; c:3; a:3>, <f:4; c:3; a:3; b:1> が来るが、共通するパタンは< f:3; c:3; a:3>だけ。 • そこで、mine(< f:3; c:3; a:3>|m)を実行すると(am:3),(cm:3),(fm:3)が得られる。 • 次に、mine(< f:3; c:3>|am)を実行すると、(cam:3),(fam:3)が得られる。 • さらに(<f:3>|cam)を実行すると、(fcam:3)が得られる。 以下他のパタンについても同様。
Conditional FP-tree は、条件のitem(例えば1番上の例だと p)のcountに合わせる。
パタン・マイニング・アルゴリズム • Input: FP-tree constructed based on Algorithm 1,using DB and a minimum support threshold ξ. • Output: The complete set of frequent patterns. • Method: Call FP-growth (FP-tree ; null). Procedure FP-growth (Tree、α ) { if Tree contains a single path P then for each combination (denoted as β )of the nodes in the path P do {generate pattern β∪α [ with support =minimum support of nodes in β]} else for each ai in the header of Tree do {generate pattern β= ai∪α [ withsupport = ai :support}; construct 's conditional pattern base; β‘s conditional FP-tree :Treeβ; if Tree β≠Ø then call FP-growth (Treeβ, β) } }
その他 • 分類階層つき相関ルール • 並列アルゴリズム • 視覚化手法