Market Basket Analysis in Python
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School
$$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)}$$
$$Zhang(A \rightarrow B) = $$ $$\frac{Support(A \& B) - Support(A) Support(B)}{ Max[Support(AB) (1-Support(A)), Support(A)(Support(B)-Support(AB))]}$$
# 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()
# 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
Market Basket Analysis in Python