高度なルール

Python で学ぶマーケットバスケット分析

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

マーケットバスケット分析の概要

  • マーケットバスケット分析の標準手順
    1. 大量のルールを生成
    2. 指標でルールを絞り込み
    3. 直感と常識で見直し
Python で学ぶマーケットバスケット分析

ルールの生成

  • アイテム数に対しルール数は指数関数的に増加
    • ほとんどのルールは有用でない
  • まず初期フィルタリングが必須
    • 第3章のAprioriアルゴリズムで解説
Python で学ぶマーケットバスケット分析

フィルタリングはどう機能するか

ID antecedents consequents support Lift
1 Harry Potter The Hunger Games 0.001 1.01
2 Hunger Games Twilight 0.020 1.23
3 Pride and Prejudice The Hobbit 0.030 1.05
4 The Hobbit Twilight 0.015 0.85
5 Harry Potter The Hobbit 0.010 1.07
Python で学ぶマーケットバスケット分析

複数指標フィルタリング

ID antecedents consequents support zhang
1 Harry Potter The Hunger Games 0.001 -0.05
2 Hunger Games Twilight 0.020 0.17
3 Pride and Prejudice The Hobbit 0.030 0.06
4 The Hobbit Twilight 0.015 -0.04
5 Harry Potter The Hobbit 0.010 0.34
Python で学ぶマーケットバスケット分析

複数指標でのフィルタリング実行

print(rules.head())
  antecedents consequents  antecedent support  ... support  confidence  ... conviction  
0 Potter      Hunger       0.48                ...  0.12  ... 0.26      ...  0.92
1 Potter      Hunger       0.32                ...  0.12  ... 0.26      ...  0.92 
2 Twilight    Hunger       0.26                ...  0.09  ... 0.35      ...  1.04
3 Hunger      Twilight     0.32                ...  0.09  ... 0.28      ...  1.03 
4 Mockingbird Hunger       0.48                ...  0.10  ... 0.20      ...  0.85
Python で学ぶマーケットバスケット分析

複数指標でのフィルタリング実行

# 結果側サポートが低いルールを抽出
rules = rules[rules['consequent support'] < 0.05]
print(len(rules))
12
# lift > 1.5 のルールを抽出
rules = rules[rules['lift'] > 1.5]
print(len(rules))
2
Python で学ぶマーケットバスケット分析

練習しましょう!

Python で学ぶマーケットバスケット分析

Preparing Video For Download...