Leverage and conviction

Market Basket Analysis in Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Building on simpler metrics

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

Market Basket Analysis in Python

The leverage metric

  • Leverage also builds on support.

 

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

  • Leverage is similar to lift, but easier to interpret.
  • Leverage lies in -1 and +1 range.
    • Lift ranges from 0 to infinity.
Market Basket Analysis in Python

Computing 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
Market Basket Analysis in Python

The conviction metric

  1. Conviction is also built using support.
  2. More complicated and less intuitive than leverage.

 

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

Market Basket Analysis in Python

Interpreting conviction

A thumbnail image of Twilight.

A thumbnail image of Harry Potter and the Sorcerer's Stone.

A thumbnail image of Twilight.

A thumbnail image of the Hunger Games.

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

Computing 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
Market Basket Analysis in Python

Let's practice!

Market Basket Analysis in Python

Preparing Video For Download...