探索批發客戶叢集
延續你在批發資料集上的工作,現在你已經可以開始分析這些叢集的特性。
因為你處理的維度超過 2 個,要用散佈圖來視覺化叢集會很困難;因此,這裡改以摘要統計來探索叢集。在本練習中,你將分析每個叢集中三個類別的平均花費。
本練習屬於課程
R 的叢集分析
練習說明
- 使用
count()計算每個叢集的大小。 - 以高度 15,000 著色並繪製樹狀圖(dendrogram)。
- 使用
summarise_all()函式計算各叢集內每個類別的平均花費。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
dist_customers <- dist(customers_spend)
hc_customers <- hclust(dist_customers)
clust_customers <- cutree(hc_customers, h = 15000)
segment_customers <- mutate(customers_spend, cluster = clust_customers)
# Count the number of customers that fall into each cluster
count(___, ___)
# Color the dendrogram based on the height cutoff
dend_customers <- as.dendrogram(hc_customers)
dend_colored <- color_branches(___, ___)
# Plot the colored dendrogram
# Calculate the mean for each category
segment_customers %>%
group_by(cluster) %>%
summarise_all(list(mean))