開始使用免費開始

以 lift 製作熱度圖

創辦人很喜歡你為她的串流服務製作的熱度圖。不過在進一步討論專案後,你們認為在決定要授權哪些電影之前,還需要看看其他指標。特別是,創辦人建議你選一個能告訴你:在考量各部電影的單獨支持度之後,實際的支持度是否高於預期的指標。

你想起 lift 很適合這個目的,決定用它當作指標。你也記得 lift 在 1.0 有個重要的門檻,因此決定把色帶改成標註,這樣你就能判斷某個值是否大於 1.0。請注意,上一題產生的規則已以 rules 提供給你。

本練習屬於課程

Python 的 Market Basket Analysis

檢視課程

練習說明

  • 以標準別名匯入 seaborn
  • 使用 lift 指標,將包含規則的 DataFrame 轉換為矩陣。
  • 繪製熱度圖,開啟標註並關閉色帶。

動手互動練習

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

# Import seaborn under its standard alias
____

# Transform the DataFrame of rules into a matrix using the lift metric
pivot = rules.____(index = 'consequents', 
                   columns = 'antecedents', values= '____')

# Generate a heatmap with annotations on and the colorbar off
sns.heatmap(pivot, annot = ____, ____)
plt.yticks(rotation=0)
plt.xticks(rotation=90)
plt.show()
編輯並執行程式碼