Güven ve lift

Python ile Market Basket Analysis

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Destek yanıltıcı olduğunda

TID İşlem
1 Kahve, Süt
2 Ekmek, Süt, Portakal
3 Ekmek, Süt
4 Ekmek, Süt, Şeker
5 Ekmek, Reçel, Süt
... ...

 

  1. Süt ve ekmek sık birlikte alınır.
    • Destek: {Milk} $\rightarrow$ {Bread}
  2. Kural pazarlama için bilgilendirici değil.
    • Süt ve ekmek zaten popüler ürünler.
Python ile Market Basket Analysis

Confidence metriği

  1. support üzerine ek metriklerle iyileştirilebilir.
  2. confidence eklemek tabloyu daha netleştirir.

 

$$\frac{Support(X \& Y)}{Support(X)}$$

Python ile Market Basket Analysis

Confidence metriğini yorumlama

Bu görsel bir marketten işlem listesini gösterir. İşlemlerden birinde reçel ve ekmek vardır.

$$Support(Milk\&Coffee) = 0.20$$

Bu görsel bir marketten işlem listesini gösterir. İşlemlerden birinde reçel ve ekmek vardır.

$$Support(Milk) = 1.00$$

Python ile Market Basket Analysis

Confidence metriğini yorumlama

  $$\frac{Support(Milk\&Coffee)}{Support(Milk)} = \frac{0.20}{1.00} = 0.20$$

  $$\frac{Support(Milk\&Coffee)}{Support(Milk)} = \frac{0.20}{0.80} = 0.25$$

  $$\frac{Support(Milk\&Coffee)}{Support(Milk)} = \frac{0.20}{0.20} = 1.00$$

Python ile Market Basket Analysis

Lift metriği

 

  • Lift, öğeler arasındaki ilişkiyi değerlendirmek için başka bir metrik sağlar.
    • Pay: X ve Y içeren işlemlerin oranı.
    • Payda: X ve Y rastgele ve bağımsız atansaydı oluşacak oran.

 

$$\frac{Support(X \& Y)}{Support(X) Support(Y)}$$

Python ile Market Basket Analysis

Veriyi hazırlama

from mlxtend.preprocessing import TransactionEncoder
import pandas as pd

# Split library strings into lists
libraries = data['Library'].apply(lambda t: t.split(','))

# Convert to list of lists
libraries = list(libraries)

# One-hot encode books
books = TransactionEncoder().fit(libraries).transform(libraries)

# Convert one-hot encoded data to DataFrame
books = pd.DataFrame(books, columns = encoder.columns_)
Python ile Market Basket Analysis

Confidence ve lift hesaplama

# Print first five items
print(books.head())
       Hunger           Gatsby
0      False            True
1      False            True
2      False            False
3      False            True
4      False            True

Veri kümesi: GoodBooks-10K.

Python ile Market Basket Analysis

Confidence ve lift hesaplama

# Computing support.
supportHG = np.logical_and(books['Hunger'],books['Gatsby']).mean()
supportH = books['Hunger'].mean()
supportG = books['Gatsby'].mean()
# Compute and print confidence and lift.
confidence = supportHG / supportH
lift = supportHG / (supportH * supportG)
# Print results.
print(supportG, confidence, lift)
(0.30, 0.16, 0.53)
Python ile Market Basket Analysis

Hadi pratik yapalım!

Python ile Market Basket Analysis

Preparing Video For Download...