Metrik paling sederhana

Analisis Market Basket dengan Python

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

Metrik dan pruning

  • Sebuah metrik mengukur kinerja aturan.
    • {humor} $\rightarrow$ {poetry}
      • 0,81
    • {fiction} $\rightarrow$ {travel}
      • 0,23
  • Pruning adalah penggunaan metrik untuk membuang aturan.
    • Pertahankan: {humor} $\rightarrow$ {poetry}
    • Buang: {fiction} $\rightarrow$ {travel}
Analisis Market Basket dengan Python

Metrik paling sederhana

  • Metrik support mengukur porsi transaksi yang memuat suatu itemset.

 

$$\frac{\text{jumlah transaksi dengan item}}{\text{jumlah transaksi}}$$

 

$$\frac{\text{jumlah transaksi dengan milk}}{\text{total transaksi}}$$

Analisis Market Basket dengan Python

Support untuk language

TID Transaksi
0 travel, humor, fiction
1 humor, language
2 humor, biography, cooking
3 cooking, language
4 travel

 

Support untuk {language} = 2 / 10 = 0,2

TID Transaksi
5 poetry, health, travel, history
6 humor
7 travel
8 poetry, fiction, humor
9 fiction, biography
Analisis Market Basket dengan Python

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

TID Transaksi
0 travel,humor,fiction
1 humor,language
2 humor,biography,cooking
3 cooking,language
4 travel

 

SUPPORT untuk {language} $\rightarrow$ {humor} = 0,1

TID Transaksi
5 poetry,health,travel,history
6 humor
7 travel
8 poetry,fiction,humor
9 fiction,biography
Analisis Market Basket dengan Python

Menyiapkan data

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

Menyiapkan data

# 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
Analisis Market Basket dengan Python

Menghitung support untuk item tunggal

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
Analisis Market Basket dengan Python

Menghitung support untuk beberapa item

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
Analisis Market Basket dengan Python

Ayo berlatih!

Analisis Market Basket dengan Python

Preparing Video For Download...