मल्टीपल मेट्रिक्स के साथ एडवांस्ड फ़िल्टरिंग
पहले, हमने एक ऑनलाइन नवेल्टी गिफ्ट स्टोर के डेटा से ऐसे antecedents ढूँढ़े थे जिनकी मदद से किसी चुने हुए consequent को प्रमोट किया जा सके. संभावित नियमों का सेट बड़ा था, इसलिए हमें इसे सीमित करने के लिए Apriori एल्गोरिदम और मल्टी-मेट्रिक फ़िल्टरिंग पर भरोसा करना पड़ा. इस अभ्यास में, हम सभी नियमों के पूरे सेट की जाँच करेंगे और एक उपयोगी नियम ढूँढ़ेंगे, किसी एक विशेष antecedent को टार्गेट करने के बजाय.
ध्यान दें कि डेटा लोड, प्री-प्रोसेस और वन-हॉट एन्कोड किया जा चुका है, और onehot के रूप में उपलब्ध है. इसके अलावा, mlxtend से apriori() और association_rules() इम्पोर्ट किए गए हैं. इस अभ्यास में, आप frequent itemsets पहचानने के लिए Apriori एल्गोरिदम लागू करेंगे. फिर आप इन itemsets से association rules निकालेंगे और मल्टी-मेट्रिक फ़िल्टरिंग लागू करेंगे.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Market Basket Analysis
अभ्यास निर्देश
- वन-हॉट एन्कोड किए गए itemsets पर Apriori एल्गोरिदम 0.001 के न्यूनतम support थ्रेशहोल्ड के साथ लागू करें.
- 0.001 के न्यूनतम support थ्रेशहोल्ड के साथ association rules एक्सट्रैक्ट करें.
antecedent_supportको 0.002 औरconsequent_supportको 0.01 पर सेट करें.confidenceको 0.60 से अधिक औरliftको 2.50 से अधिक सेट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Apply the Apriori algorithm with a minimum support threshold of 0.001
frequent_itemsets = ____(onehot, min_support = ____, use_colnames = True)
# Recover association rules using a minium support threshold of 0.001
rules = ____(frequent_itemsets, metric = '____', min_threshold = 0.001)
# Apply a 0.002 antecedent support threshold, 0.60 confidence threshold, and 2.50 lift threshold
filtered_rules = rules[(rules['antecedent support'] > ____) &
(____['consequent support'] > 0.01) &
(rules['____'] > ____) &
(____ > 2.50)]
# Print remaining rule
print(filtered_rules[['antecedents','consequents']])