Leverage 與 conviction

Python 的 Market Basket Analysis

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)}$$

Python 的 Market Basket Analysis

Leverage 指標

  • Leverage 也建立在 support 之上。

 

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

  • Leverage 類似 lift,但更容易解讀
  • Leverage 介於 -1 到 +1
    • Lift 介於 0 到無窮大。
Python 的 Market Basket Analysis

計算 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
Python 的 Market Basket Analysis

Conviction 指標

  1. Conviction 也由 support 建立。
  2. leverage 更複雜、直覺性較低。

 

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

Python 的 Market Basket Analysis

解讀 conviction

《暮光之城》縮圖。

《哈利波特:神秘的魔法石》縮圖。

《暮光之城》縮圖。

《飢餓遊戲》縮圖。

1 圖片來源:goodreads.com。
Python 的 Market Basket Analysis

計算 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
Python 的 Market Basket Analysis

一起來練習吧!

Python 的 Market Basket Analysis

Preparing Video For Download...