Độ tin cậy và lift

Phân tích giỏ hàng trong Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Khi support gây hiểu lầm

TID Giao dịch
1 Coffee, Milk
2 Bread, Milk, Orange
3 Bread, Milk
4 Bread, Milk, Sugar
5 Bread, Jam, Milk
... ...

 

  1. Sữa và bánh mì thường được mua cùng nhau.
    • Support: {Milk} $\rightarrow$ {Bread}
  2. Quy tắc không hữu ích cho marketing.
    • Cả sữa và bánh mì đều phổ biến.
Phân tích giỏ hàng trong Python

Chỉ số confidence

  1. Có thể cải thiện so với support bằng chỉ số bổ sung.
  2. Thêm confidence giúp bức tranh đầy đủ hơn.

 

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

Phân tích giỏ hàng trong Python

Diễn giải chỉ số confidence

Hình này hiển thị danh sách giao dịch ở cửa hàng tạp hóa. Một giao dịch có jam và bread.

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

Hình này hiển thị danh sách giao dịch ở cửa hàng tạp hóa. Một giao dịch có jam và bread.

$$Support(Milk) = 1.00$$

Phân tích giỏ hàng trong Python

Diễn giải chỉ số confidence

  $$\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$$

Phân tích giỏ hàng trong Python

Chỉ số lift

 

  • Lift là chỉ số khác để đánh giá quan hệ giữa các mục.
    • Tử số: Tỷ lệ giao dịch chứa X và Y.
    • Mẫu số: Tỷ lệ nếu X và Y xuất hiện ngẫu nhiên, độc lập.

 

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

Phân tích giỏ hàng trong Python

Chuẩn bị dữ liệu

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_)
Phân tích giỏ hàng trong Python

Tính độ tin cậy và lift

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

Dataset: GoodBooks-10K.

Phân tích giỏ hàng trong Python

Tính độ tin cậy và lift

# 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)
Phân tích giỏ hàng trong Python

Ayo berlatih!

Phân tích giỏ hàng trong Python

Preparing Video For Download...