सबसे सरल मेट्रिक

Python में Market Basket Analysis

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

मेट्रिक्स और प्रूनिंग

  • मेट्रिक नियमों के प्रदर्शन का माप है.
    • {humor} $\rightarrow$ {poetry}
      • 0.81
    • {fiction} $\rightarrow$ {travel}
      • 0.23
  • Pruning मतलब मेट्रिक से कमजोर नियम हटाना.
    • रखें: {humor} $\rightarrow$ {poetry}
    • हटाएँ: {fiction} $\rightarrow$ {travel}
Python में Market Basket Analysis

सबसे सरल मेट्रिक

  • support मेट्रिक उन transactions का हिस्सा मापता है जिनमें कोई itemset आता है.

 

$$\frac{\text{number of transactions with items(s)}}{\text{number of transactions}}$$

 

$$\frac{\text{number of transactions with milk}}{\text{total transactions}}$$

Python में Market Basket Analysis

language का support

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

 

{language} का support = 2 / 10 = 0.2

TID Transaction
5 poetry, health, travel, history
6 humor
7 travel
8 poetry, fiction, humor
9 fiction, biography
Python में Market Basket Analysis

{Humor} $\rightarrow$ {Language} का support

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

 

{language} $\rightarrow$ {humor} का SUPPORT = 0.1

TID Transaction
5 poetry,health,travel,history
6 humor
7 travel
8 poetry,fiction,humor
9 fiction,biography
Python में Market Basket Analysis

डेटा तैयार करना

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

डेटा तैयार करना

# 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 में Market Basket Analysis

एकल items के लिए support निकालना

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 में Market Basket Analysis

एकाधिक items के लिए support निकालना

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 में Market Basket Analysis

अभ्यास करते हैं!

Python में Market Basket Analysis

Preparing Video For Download...