關聯與離關

Python 的 Market Basket Analysis

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

用離關配對電子書

《哈比人歷險記》書封縮圖。

《大亨小傳》書封縮圖。

《傲慢與偏見》書封縮圖。

《麥田捕手》書封縮圖。

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

Zhang 指標介紹

  1. Zhang(2000)提出
    • 取值介於 -1 到 +1 之間
    • +1 表示完全關聯
    • -1 表示完全離關
  2. 完整且可解釋
  3. 以 support 構成
1 Zhang, T. (2000). Association Rules. Proceedings of the 4th Pacific-Asia conference, PADKK, pp.245-256. Kyoto, Japan.
Python 的 Market Basket Analysis

Zhang 指標的定義

  $$Zhang(A \rightarrow B) = $$ $$\frac{Confidence(A \rightarrow B) - Confidence(\bar{A} \rightarrow B)}{Max[Confidence(A \rightarrow B), Confidence(\bar{A} \rightarrow B)]}$$   $$Confidence = \frac{Support(A \& B)}{Support(A)}$$

Python 的 Market Basket Analysis

用 support 構成 Zhang 指標

  $$Zhang(A \rightarrow B) = $$ $$\frac{Support(A \& B) - Support(A) Support(B)}{ Max[Support(AB) (1-Support(A)), Support(A)(Support(B)-Support(AB))]}$$

Python 的 Market Basket Analysis

計算 Zhang 指標

# Compute the support of each book
supportH = hobbit.mean()
supportP = pride.mean()
# Compute the support of both books
supportHP = np.logical_and(hobbit, pride).mean()
Python 的 Market Basket Analysis

計算 Zhang 指標

# Compute the numerator
num = supportHP - supportH*supportP
# Compute the denominator
denom = max(supportHP*(1-supportH), supportH*(supportP-supportHP))
# Compute Zhang's metric
zhang = num / denom
print(zhang)
0.08903
Python 的 Market Basket Analysis

一起來練習吧!

Python 的 Market Basket Analysis

Preparing Video For Download...