開始使用免費開始

使用多重指標的進階篩選

先前我們使用一家線上創意禮品店的資料,找出可用來促銷特定後件(consequent)的前件(antecedent)。由於可能的規則集合很大,我們必須依賴 Apriori 演算法與多重指標篩選來縮小範圍。在這個練習中,我們會檢視完整的規則集合並找出一條有用的規則,而不是鎖定某個特定的前件。

請注意,資料已載入、前處理並完成 one-hot 編碼,可由 onehot 取得。此外,mlxtend 中的 apriori()association_rules() 已經匯入。在本練習中,你將套用 Apriori 演算法以找出頻繁項集。接著,從這些項集中產生關聯規則,並套用多重指標篩選。

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 以最小支持度門檻 0.001,將 Apriori 演算法套用到 one-hot 編碼的項集。
  • 使用最小支持度門檻 0.001 萃取關聯規則。
  • 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']])
編輯並執行程式碼