開始使用免費開始

support-confidence 邊界的最佳性

你帶著上一個練習產生的散佈圖回去找創辦人,並詢問她是否希望你使用修剪來復原 support-confidence 邊界。你向她說明了 Bayardo-Agrawal 的結果,但她似乎半信半疑,要求你用一個範例示範。

想到散佈圖可以依據第三個指標來縮放點的大小,你決定用這點來展示 support-confidence 邊界的最佳性。你會用 lift 指標來縮放點的大小,這正是 Bayardo-Agrawal 所適用的指標之一。one-hot 編碼後的資料已經幫你匯入為 onehot。此外,apriori()association_rules() 也已匯入,pandas 可用名稱為 pd

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 對 DataFrame onehot 套用 Apriori 演算法。
  • 使用 support 指標與最小門檻 0.0 計算關聯規則。
  • 完成散佈圖的程式,使點的大小由 lift 來縮放。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import seaborn under its standard alias
import seaborn as sns

# Apply the Apriori algorithm with a support value of 0.0075
frequent_itemsets = ____(____, min_support = 0.0075, 
                         use_colnames = True, max_len = 2)

# Generate association rules without performing additional pruning
rules = ____(frequent_itemsets, metric = "support", 
                          min_threshold = ____)

# Generate scatterplot using support and confidence
sns.scatterplot(x = "support", y = "confidence", 
                size = "____", data = rules)
plt.show()
編輯並執行程式碼