開始使用免費開始

K-means 分群的平均值

在這個練習中,你將以 K-means 的 3 群解來檢視各欄位的平均值。作為測試與學習(test & learn)探索流程的一部分,對分群結果進行視覺化檢查,是找出最符合商業需求方案的關鍵。

已匯入 seabornsns,以及 matplotlib.pyplotplt。另外,我們已經以 K-means 產生 3 群解,並將附帶分群標籤的資料集載入為 wholesale_kmeans3 DataFrame。

本練習屬於課程

Python 的行銷機器學習

檢視課程

練習說明

  • 依分群標籤分組並計算各欄位的平均值。
  • 列印每個分群的欄位平均值。
  • 以每個分群的欄位平均值建立熱圖(heatmap)。
  • 顯示圖表。

動手互動練習

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

# Group by the segment label and calculate average column values
kmeans3_averages = wholesale_kmeans3.___(['___']).___().round(0)

# Print the average column values per each segment
print(___)

# Create a heatmap on the average column values per each segment
sns.___(___.T, cmap='YlGnBu')

# Display the chart
plt.___()
編輯並執行程式碼