開始使用免費開始

用信賴度細化支持度

在上一題回報你的發現後,圖書館接著詢問關係的方向。他們應該用《哈利波特》帶動《暮光之城》,還是用《暮光之城》帶動《哈利波特》?

思考之後,你決定計算具有方向性的信賴度(confidence),不同於沒有方向性的支持度(support)。你會同時計算 {Potter} \(\rightarrow\) {Twilight}{Twilight} \(\rightarrow\) {Potter}books DataFrame 已為你匯入,其中每本書各有一欄:PotterTwilight

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 計算 {Potter, Twilight} 的 support。
  • 計算 {Potter} 的 support。
  • 計算 {Twilight} 的 support。
  • 分別計算 {Potter} \(\rightarrow\) {Twilight}{Twilight} \(\rightarrow\) {Potter} 的 confidence。

動手互動練習

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

# Compute support for Potter and Twilight
supportPT = np.logical_and(____, ____).mean()

# Compute support for Potter
supportP = books['Potter'].____

# Compute support for Twilight
supportT = ____

# Compute confidence for both rules
confidencePT = supportPT / ____
confidenceTP = ____ / supportT

# Print results
print('{0:.2f}, {1:.2f}'.format(confidencePT, confidenceTP))
編輯並執行程式碼