고급 규칙

Python으로 배우는 Market Basket Analysis

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

장바구니 분석 개요

  • 장바구니 분석 표준 절차
    1. 대량의 규칙 생성
    2. 지표로 규칙 필터링
    3. 직관과 상식 적용
Python으로 배우는 Market Basket Analysis

규칙 생성

  • 항목 수가 늘면 규칙 수는 기하급수적으로 증가
    • 대부분의 규칙은 유용하지 않음
  • 초기 필터링이 필수
    • 3장에서 Apriori 알고리즘으로 다룸
Python으로 배우는 Market Basket Analysis

필터링은 어떻게 작동하나요?

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으로 배우는 Market Basket Analysis

다중 지표 필터링

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으로 배우는 Market Basket Analysis

다중 지표 필터링 수행

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으로 배우는 Market Basket Analysis

다중 지표 필터링 수행

# 결과 지지도(consequent support)가 낮은 규칙만 선택
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으로 배우는 Market Basket Analysis

연습해 봅시다!

Python으로 배우는 Market Basket Analysis

Preparing Video For Download...