用支持度推薦書籍
某圖書館想鼓勵會員多閱讀,決定運用市場籃分析來找出方法。他們找上你進行分析,並要求使用影片中介紹過的 goodbooks-10k 資料集裡評分最高的 5 本書。你已取得以 one-hot 編碼表示的資料,存在名為 books 的 pandas DataFrame 中。
DataFrame 的每一欄對應一本書,若某位讀者的書庫中包含該書且評分很高,值為 TRUE。為了簡化,我們使用縮寫的書名:Hunger、Potter、Twilight。
本練習屬於課程
Python 的 Market Basket Analysis
練習說明
- 計算 {Hunger, Potter} 的支持度。
- 計算 {Hunger, Twilight} 的支持度。
- 計算 {Potter, Twilight} 的支持度。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Compute support for Hunger and Potter
supportHP = np.logical_and(books['Hunger'], books['____']).mean()
# Compute support for Hunger and Twilight
supportHT = ____(books['Hunger'], books['Twilight']).mean()
# Compute support for Potter and Twilight
supportPT = np.logical_and(books['Potter'], books['Twilight']).____
# Print support values
print("Hunger Games and Harry Potter: %.2f" % supportHP)
print("Hunger Games and Twilight: %.2f" % supportHT)
print("Harry Potter and Twilight: %.2f" % supportPT)