Association and dissociation

Market Basket Analysis in Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Using dissociation to pair ebooks

A thumbnail image of the book cover of The Hobbit.

A thumbnail image of the book cover of The Great Gatsby.

A thumbnail image of the book cover of Pride and Prejudice.

A thumbnail image of the book cover of The Catcher in the Rye.

1 Images taken from goodreads.com.
Market Basket Analysis in Python

Introduction to Zhang's metric

  1. Introduced by Zhang (2000)
    • Takes values between -1 and +1
    • Value of +1 indicates perfect association
    • Value of -1 indicates perfect dissociation
  2. Comprehensive and interpretable
  3. Constructed using support
1 Zhang, T. (2000). Association Rules. Proceedings of the 4th Pacific-Asia conference, PADKK, pp.245-256. Kyoto, Japan.
Market Basket Analysis in Python

Defining Zhang's metric

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

Market Basket Analysis in Python

Constructing Zhang's metric using support

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

Market Basket Analysis in Python

Computing Zhang's metric

# 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()
Market Basket Analysis in Python

Computing Zhang's metric

# 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

Let's practice!

Market Basket Analysis in Python

Preparing Video For Download...