開始使用免費開始

用散佈圖進行修剪

在檢視你前一題以蝙蝠俠為主題的串流服務提案後,創辦人意識到最初的計畫可能太過狹隘。她不再聚焦於特定片名,而是請你改以關聯規則中的整體模式為主,並據此進行修剪。你的目標是找出一大組強關聯。

所幸你剛學會如何產生散佈圖。你決定先繪製 support 與 confidence,因為依據許多常見指標,最佳規則通常落在 confidence-support 的邊界上。已為你匯入經 one-hot 編碼的資料,可透過 onehot 取得。此外,apriori()association_rules() 已匯入,pandas 也已以 pd 可用。

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 產生大量由 2 個項目組成的項目集:將最小 support 設為 0.0075,並將最大長度設為 2。
  • 完成 association_rules() 的敘述,避免額外的篩選。
  • 完成產生散佈圖的敘述,將 y 變數設為使用 confidence

動手互動練習

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

# Import seaborn under its standard alias
import seaborn as sns

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

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

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