关联与解关联

Python 中的购物篮分析

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

用解关联来配对电子书

《霍比特人》封面缩略图。

《了不起的盖茨比》封面缩略图。

《傲慢与偏见》封面缩略图。

《麦田里的守望者》封面缩略图。

1 图片来自 goodreads.com。
Python 中的购物篮分析

Zhang 指标简介

  1. 由 Zhang(2000)提出
    • 取值范围为 -1 到 +1
    • +1 表示完全关联
    • -1 表示完全解关联
  2. 全面且易解释
  3. 由支持度构造
1 Zhang, T. (2000). Association Rules. Proceedings of the 4th Pacific-Asia conference, PADKK, pp.245-256. Kyoto, Japan.
Python 中的购物篮分析

定义 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 中的购物篮分析

用支持度构造 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 中的购物篮分析

计算 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 中的购物篮分析

计算 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 中的购物篮分析

开始练习!

Python 中的购物篮分析

Preparing Video For Download...