Confidence के साथ pruning
एक बार फिर आप उलझ गए हैं: आपने कई काम की rules ढूँढ लीं, लेकिन उन्हें एक तक सीमित नहीं कर पा रहे हैं. और भी बुरा यह कि जो दो rules मिलीं, वे एक ही itemset से बनी थीं, बस antecedents और consequents अदला-बदली थे. आप तय करते हैं कि किसी दूसरे metric से pruning करके देखें, ताकि शायद एक ही association rule तक बात सिमट जाए.
सही metric क्या होगा? किसी भी itemset से बनने वाली सभी rules के लिए lift और support एक जैसे होते हैं, इसलिए आप confidence का उपयोग करने का निर्णय लेते हैं, जो उसी itemset से बनी rules में अलग-अलग हो सकता है. ध्यान दें कि pandas pd नाम से उपलब्ध है और one-hot encoded transaction डेटा onehot नाम से उपलब्ध है. इसके अलावा, apriori को mlxtend से इम्पोर्ट किया जा चुका है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Market Basket Analysis
अभ्यास निर्देश
mlxtendसेassociation_rulesइम्पोर्ट करें.aprioriएल्गोरिदम के लिए स्टेटमेंट पूरा करें, जहाँ support का मान 0.0015 हो और अधिकतम itemset लंबाई 2 हो.- association rules के लिए स्टेटमेंट पूरा करें, जहाँ metric के रूप में confidence और threshold मान 0.5 हो.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the association rules function
____
# Compute frequent itemsets using the Apriori algorithm
frequent_itemsets = ____(onehot, ____,
____, use_colnames = True)
# Compute all association rules using confidence
rules = ____(frequent_itemsets,
metric = "____",
min_threshold = ____)
# Print association rules
print(rules)