Apriori एल्गोरिदम

Python में Market Basket Analysis

Isaiah Hull

Visiting Associate Professor of Finance, BI Norwegian Business School

आइटमसेट गिनना

$${n \choose k} = \frac{n!}{(n-k)!k!}$$

आइटम काउंट आइटमसेट साइज कॉम्बिनेशन
3461 0 1
3461 1 3461
3461 2 5,987,530
3461 3 6,903,622,090
3461 4 5,968,181,296,805
Python में Market Basket Analysis

आइटमसेट गिनना

$$\sum_{k=0}^{n}{n \choose k} = 2^{n}$$

  • $n = 3461 \rightarrow 2^{3461}$
  • $2^{3461}>>10^{82}$
  • ब्रह्मांड में परमाणुओं की संख्या: $10^{82}$.
Python में Market Basket Analysis

आइटमसेट की संख्या घटाना

  • सभी आइटमसेट पर विचार करना असंभव।
    • उन्हें एन्यूमरेट करना भी संभव नहीं।
  • किसे बिना इवाल्यूएट किए हटाएँ?
    • अधिकतम $k$ मान तय कर सकते हैं।
  • Apriori एल्गोरिदम एक विकल्प देता है।
    • सभी आइटमसेट की एन्यूमरेशन नहीं चाहिए।
    • प्रूनिंग के लिए समझदारी का नियम।
Python में Market Basket Analysis

Apriori प्रिंसिपल

  • Apriori प्रिंसिपल.
    • फ़्रीक्वेंट सेट के सबसेट भी फ़्रीक्वेंट होते हैं।
    • जो फ़्रीक्वेंट हों, उन्हें रखें।
    • जो फ़्रीक्वेंट न हों, उन्हें प्रून करें।
  • Candles = Infrequent
    • -> {Candles, Signs} = Infrequent
  • {Candles, Signs} = Infrequent
    • -> {Candles, Signs Boxes} = Infrequent
  • {Candles, Signs, Boxes} = Infrequent
    • -> {Candles, Signs, Boxes, Bags} = Infrequent
Python में Market Basket Analysis

Apriori इम्प्लीमेंटेशन

# Import Apriori algorithm
from mlxtend.frequent_patterns import apriori

# Load one-hot encoded novelty gifts data
onehot = pd.read_csv('datasets/online_retail_onehot.csv')

# Print header.
print(onehot.head())
    50'S CHRISTMAS GIFT BAG LARGE ...  ZINC WILLIE WINKIE  CANDLE STICK  \
0                           False ...              False   
1                           False ...              False   
2                           False ...              False   
3                           False ...              False   
4                           False ...              False
Python में Market Basket Analysis

Apriori इम्प्लीमेंटेशन

# Compute frequent itemsets
frequent_itemsets = apriori(onehot, min_support = 0.0005, 
                            max_len = 4, use_colnames = True)

# Print number of itemsets
print(len(frequent_itemsets))
3652
Python में Market Basket Analysis

Apriori इम्प्लीमेंटेशन

# Print itemsets
print(frequent_itemsets.head())
      support                          itemsets
0     0.000752  ( 50'S CHRISTMAS GIFT BAG LARGE)
1     0.001504              ( DOLLY GIRL BEAKER)
...
1500  0.000752  (PING MICROWAVE APRON, FOOD CONTAINER SET 3 LO...
1501  0.000752  (WOOD 2 DRAWER CABINET WHITE FINISH, FOOD CONT...
...
Python में Market Basket Analysis

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

Python में Market Basket Analysis

Preparing Video For Download...