SlideShare une entreprise Scribd logo
1  sur  15
バスケット分析のルール探索に
データフレームを使いたい
1.{arules} 用の拡張パッケージを作りました
第11回fukuoka.R(#fukuokaR)
Introduction of inspectDF package
@kato_kohaku
• 臨床検査事業 の なかのひと
?専門
• 遊牧@モンゴル → 臨床検査事業の研究所
• 生態学/環境科学 → 医療情報学/疫学
1cm
誰?
マーケットバスケット分析
• 「おむつとビール」で有名なアレ
• アソシエーション分析、関連ルールマイニングとかいろいろ呼ばれる
• トランザクションデータベースに頻出する、アイテム間の何らかの組み合わせ規則
をとりだす
用語
• ルールの条件部(lhs)
• 結論部(rhs)
• 支持度:support(X ⇒ Y)
• アイテムX,Yを同時に含むトランザクションが、データ中に占める比率
• 確信度:confidence(X ⇒ Y)
• アイテム X が含まれるトランザクション中に、アイテム Y も同時に含まれる比率
• リフト:lift (X ⇒ Y)
• 確信度をトランザクションにYが含まれる頻度で補正したもの、有効性の指標
LHS => RHS
{"パン","オムツ", "ハム"} => {"ビール“}
arulesパッケージ
• Aprioriアルゴリズムに基づいた相関ルールを検出する
標準ツールでのルール探索がつらい
• 標準の、print(), summary()がそっけない
• 標準の、subset()をはじめとする関数のつかいかたを覚えたくない
→ data frame + dplyr&etc. で探索したい
モチベーション
「モダン」な探索に向けて
• ルールリスト を データフレーム で 扱いたい
• (一応) inspect() 内のprint()の副作用でデータフレームの取得は可能
→ コンソールに全部出力される
• 体裁(=>)のためだけに、無名のカラムを含むdata frameが出力される
モチベーション
作った:inspectDFパッケージ
• arules::inspect()をinvisibleにdata.frameで出力する
• arules::inspect() の代わりに inspectDF() するだけ。
inspectDF package
作った:inspectDFパッケージ
• それぞれのカラムを取り出すための関数は、arules標準で用意されている
• 自分が作ったのは、LHSに含まれるアイテム数 (n.lhs) だけ
inspectDF package
インストール
• Github から
• https://github.com/katokohaku/inspectDF
inspectDF package
「モダン」な探索例
1. 条件部に、yogurt または sausage を含むルールのうち、
2. 確信度→リフト値の高い順に、
3. アイテムが2つ以上のルールを、
4. 上位5件
inspectDF package
探索したルールのグラフ描画
inspectDF package
カスタマイズ可視化向け
• グラフ用データフレームに変換
inspectDF package
余談:アイテム名とセパレータ
• アイテム名に“,”が含まれることがある
• たとえば DHA
inspectDF package
余談:アイテム名とセパレータ
• アイテム名に“,”が含まれることがある
• sepオプションで好きな文字列をセパレータに指定可能
• もともとのarulesの機能を継承しただけ
inspectDF package
参考
• フリーソフトによるデータ解析・マイニング
• アソシエーション分析(1)
• https://www.cis.doshisha.ac.jp/mjin/R/40/40.html
• アソシエーション分析(2)
• https://www1.doshisha.ac.jp/~mjin/R/Chap_41/41.html
• グラフプロット
• マーケットバスケット分析の結果をRパッケージigraphを使って可視化する
• https://qiita.com/hideaki/items/8066a635e61ee0d1b389

Contenu connexe

Plus de Satoshi Kato

Multiple optimization and Non-dominated sorting with rPref package in R
Multiple optimization and Non-dominated sorting with rPref package in RMultiple optimization and Non-dominated sorting with rPref package in R
Multiple optimization and Non-dominated sorting with rPref package in RSatoshi Kato
 
Deep forest (preliminary ver.)
Deep forest  (preliminary ver.)Deep forest  (preliminary ver.)
Deep forest (preliminary ver.)Satoshi Kato
 
Introduction of "the alternate features search" using R
Introduction of  "the alternate features search" using RIntroduction of  "the alternate features search" using R
Introduction of "the alternate features search" using RSatoshi Kato
 
forestFloorパッケージを使ったrandomForestの感度分析
forestFloorパッケージを使ったrandomForestの感度分析forestFloorパッケージを使ったrandomForestの感度分析
forestFloorパッケージを使ったrandomForestの感度分析Satoshi Kato
 
Oracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoOracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoSatoshi Kato
 
Imputation of Missing Values using Random Forest
Imputation of Missing Values using  Random ForestImputation of Missing Values using  Random Forest
Imputation of Missing Values using Random ForestSatoshi Kato
 
Interpreting Tree Ensembles with inTrees
Interpreting Tree Ensembles with  inTreesInterpreting Tree Ensembles with  inTrees
Interpreting Tree Ensembles with inTreesSatoshi Kato
 

Plus de Satoshi Kato (7)

Multiple optimization and Non-dominated sorting with rPref package in R
Multiple optimization and Non-dominated sorting with rPref package in RMultiple optimization and Non-dominated sorting with rPref package in R
Multiple optimization and Non-dominated sorting with rPref package in R
 
Deep forest (preliminary ver.)
Deep forest  (preliminary ver.)Deep forest  (preliminary ver.)
Deep forest (preliminary ver.)
 
Introduction of "the alternate features search" using R
Introduction of  "the alternate features search" using RIntroduction of  "the alternate features search" using R
Introduction of "the alternate features search" using R
 
forestFloorパッケージを使ったrandomForestの感度分析
forestFloorパッケージを使ったrandomForestの感度分析forestFloorパッケージを使ったrandomForestの感度分析
forestFloorパッケージを使ったrandomForestの感度分析
 
Oracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslassoOracle property and_hdm_pkg_rigorouslasso
Oracle property and_hdm_pkg_rigorouslasso
 
Imputation of Missing Values using Random Forest
Imputation of Missing Values using  Random ForestImputation of Missing Values using  Random Forest
Imputation of Missing Values using Random Forest
 
Interpreting Tree Ensembles with inTrees
Interpreting Tree Ensembles with  inTreesInterpreting Tree Ensembles with  inTrees
Interpreting Tree Ensembles with inTrees
 

Introduction of inspectDF package