開始使用免費開始

計算 conviction(信念度)

在圖書館的建議大獲好評後,一家小型電子書新創的創辦人找上你進行顧問合作。為了測試你的能力,她要你計算規則 {Potter} \(\rightarrow\) {Hunger} 的 conviction(信念度),以便決定是否要在公司網站上把這兩本書放在彼此相鄰的位置。所幸你仍可存取 goodreads-10k 資料,變數為 books。另外,pandas 已匯入為 pdnumpy 已匯入為 np

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 計算 {Potter} 的支持度,指定給 supportP
  • 計算 NOT {Hunger} 的支持度。
  • 計算 {Potter} 且 NOT {Hunger} 的支持度。
  • 在 return 陳述式中完成 conviction(信念度)指標的運算式。

動手互動練習

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

# Compute support for Potter AND Hunger
supportPH = np.logical_and(books['Potter'], books['Hunger']).mean()

# Compute support for Potter
supportP = ____.mean()

# Compute support for NOT Hunger
supportnH = 1.0 - books['____'].mean()

# Compute support for Potter and NOT Hunger
supportPnH = ____ - supportPH

# Compute and print conviction for Potter -> Hunger
conviction = ____ * supportnH / supportPnH
print("Conviction: %.2f" % conviction)
編輯並執行程式碼