Leverage และ Conviction

Market Basket Analysis ด้วย Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

ต่อยอดจากเมตริกพื้นฐาน

$$Support(X) = \frac{Frequency(X)}{N}$$

$$Support(X \rightarrow Y) = \frac{Frequency(X \& Y)}{N}$$

$$Confidence(X \rightarrow Y) = \frac{Support(X \rightarrow Y)} {Support(X)}$$

$$Lift(X \rightarrow Y) = \frac{Support(X \rightarrow Y)}{Support(X) Support(Y)}$$

Market Basket Analysis ด้วย Python

เมตริก Leverage

  • Leverage ต่อยอดมาจาก support เช่นกัน

 

$$Leverage(X \rightarrow Y) = $$ $$Support(X \& Y) - Support(X) Support(Y)$$

  • Leverage คล้ายกับ lift แต่ ตีความง่ายกว่า
  • Leverage อยู่ในช่วง -1 ถึง +1
    • Lift มีช่วงตั้งแต่ 0 ถึงอนันต์
Market Basket Analysis ด้วย Python

การคำนวณ Leverage

# Compute support for Twilight and Harry Potter
supportTP = np.logical_and(books['Twilight'], books['Potter']).mean()

# Compute support for Twilight
supportT = books['Twilight'].mean()

# Compute support for Harry Potter
supportP = books['Potter'].mean()
# Compute and print leverage
leverage = supportTP - supportP * supportT
print(leverage)
0.018
Market Basket Analysis ด้วย Python

เมตริก Conviction

  1. Conviction สร้างขึ้นจาก support เช่นกัน
  2. ซับซ้อนกว่าและตีความได้ยากกว่า leverage

 

$$Conviction(X \rightarrow Y) = $$ $$\frac{Support(X) Support(\bar{Y})} {Support(X \& \bar{{Y}})}$$

Market Basket Analysis ด้วย Python

การตีความ Conviction

ภาพย่อของหนังสือ Twilight

ภาพย่อของหนังสือ Harry Potter and the Sorcerer's Stone

ภาพย่อของหนังสือ Twilight

ภาพย่อของหนังสือ Hunger Games

1 ภาพจาก goodreads.com
Market Basket Analysis ด้วย Python

การคำนวณ Conviction

# Compute support for Twilight and Harry Potter and Twilight
supportTP = np.logical_and(books['Twilight'], books['Potter']).mean()
supportT = books['Twilight'].mean()
# Compute support for NOT Harry Potter
supportnP = 1.0 - books['Potter'].mean()
# Compute support for Twilight and NOT Harry Potter
supportTnP = supportT - supportPT
# Compute conviction
conviction = supportT*supportnP / supportTnP
print(conviction)
1.16
Market Basket Analysis ด้วย Python

มาฝึกกันเถอะ!

Market Basket Analysis ด้วย Python

Preparing Video For Download...