開始使用免費開始

以 support 與 conviction 篩選

在影片中,我們談到你持續為一家電子書銷售新創的創辦人提供顧問服務。創辦人交給你一個名為 rules 的 DataFrame,內容是先前一位在職資料科學家的成果。它包含前件(antecedents)與後件(consequents)欄位,以及這些規則在多種衡量指標下的表現。

你的目標是對這個資料集進行多重指標篩選,找出可能有用的規則。注意,pandas 已以 pd 提供,numpynp 提供。此外,rules 已經定義並可直接使用。

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 使用 .head() 方法搭配 print 預覽資料集。
  • 選出前件 support 大於 0.05 的規則子集。
  • 選出後件 support 大於 0.02 的規則子集。
  • 選出 conviction 大於 1.01 的規則子集。

動手互動練習

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

# Preview the rules DataFrame using the .head() method
print(____)

# Select the subset of rules with antecedent support greater than 0.05
rules = rules[rules['antecedent support'] > ____]

# Select the subset of rules with a consequent support greater than 0.02
rules = rules[____]

# Select the subset of rules with a conviction greater than 1.01
rules = ____

# Print remaining rules
print(rules)
編輯並執行程式碼