En basit metrik

Python ile Market Basket Analysis

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Metrikler ve budama

  • Bir metrik, kuralların performansını ölçer.
    • {humor} $\rightarrow$ {poetry}
      • 0.81
    • {fiction} $\rightarrow$ {travel}
      • 0.23
  • Budama, kuralları elemek için metriklerin kullanılmasına denir.
    • Tut: {humor} $\rightarrow$ {poetry}
    • At: {fiction} $\rightarrow$ {travel}
Python ile Market Basket Analysis

En basit metrik

  • Destek metriği, bir öğe kümesini içeren işlemlerin payını ölçer.

 

$$\frac{\text{öğe(ler)i içeren işlem sayısı}}{\text{işlem sayısı}}$$

 

$$\frac{\text{süt içeren işlem sayısı}}{\text{toplam işlemler}}$$

Python ile Market Basket Analysis

language için destek

TID İşlem
0 travel, humor, fiction
1 humor, language
2 humor, biography, cooking
3 cooking, language
4 travel

 

{language} için destek = 2 / 10 = 0,2

TID İşlem
5 poetry, health, travel, history
6 humor
7 travel
8 poetry, fiction, humor
9 fiction, biography
Python ile Market Basket Analysis

Support: {Humor} $\rightarrow$ {Language}

TID İşlem
0 travel,humor,fiction
1 humor,language
2 humor,biography,cooking
3 cooking,language
4 travel

 

{language} $\rightarrow$ {humor} için SUPPORT = 0,1

TID İşlem
5 poetry,health,travel,history
6 humor
7 travel
8 poetry,fiction,humor
9 fiction,biography
Python ile Market Basket Analysis

Veriyi hazırlama

print(transactions)
[['travel', 'humor', 'fiction'],
...
['fiction', 'biography']]
from mlxtend.preprocessing import TransactionEncoder
# Instantiate transaction encoder
encoder = TransactionEncoder().fit(transactions)
Python ile Market Basket Analysis

Veriyi hazırlama

# One-hot encode itemsets by applying fit and transform
onehot = encoder.transform(transactions)
# Convert one-hot encoded data to DataFrame
onehot = pd.DataFrame(onehot, columns = encoder.columns_)
print(onehot)
   biography  cooking  ...  poetry  travel
0  False      False   ...   False    True
...
9  True       False   ...   False    False
Python ile Market Basket Analysis

Tek öğeler için destek hesaplama

print(onehot.mean())
biography    0.2
cooking      0.2
fiction      0.3
health       0.1
history      0.1
humor        0.5
language     0.2
poetry       0.2
travel       0.4
dtype: float64
Python ile Market Basket Analysis

Birden çok öğe için destek hesaplama

import numpy as np

# Define itemset that contains fiction and poetry
onehot['fiction+poetry'] = np.logical_and(onehot['fiction'],onehot['poetry'])

print(onehot.mean())
biography         0.2
cooking           0.2
...               ...
travel            0.4
fiction+poetry    0.1
dtype: float64
Python ile Market Basket Analysis

Hadi pratik yapalım!

Python ile Market Basket Analysis

Preparing Video For Download...