彙總與篩選
在影片中,我們協助一位禮品店店長,根據關聯規則來安排實體門市的分區。由於店面格局的限制,我們必須將分區配對成兩組商品類型。經過進階篩選技巧後,我們提出了下方的平面配置。
現在店長希望你再產出另一份平面圖提案,但採用不同的準則:每一組分區都要包含一個高支持度商品與一個低支持度商品。資料 aggregated 已替你完成彙總並做了 one-hot 編碼。此外,apriori() 與 association_rules() 已從 mlxtend 匯入。
本練習屬於課程
Python 的 Market Basket Analysis
練習說明
- 以最小支持度門檻 0.0001 產生頻繁項集。
- 找出所有最小支持度門檻為 0.0001 的規則。
- 篩選出所有前件支持度大於 0.35 的規則。
- 篩選出所有後件支持度最大值小於 0.35 的規則。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Apply the apriori algorithm with a minimum support of 0.0001
frequent_itemsets = apriori(aggregated, ____, use_colnames = True)
# Generate the initial set of rules using a minimum support of 0.0001
rules = association_rules(frequent_itemsets,
metric = "____", min_threshold = ____)
# Set minimum antecedent support to 0.35
rules = rules[____['antecedent support'] > ____]
# Set maximum consequent support to 0.35
rules = rules[____ < 0.35]
# Print the remaining rules
print(rules)