K-means 分群的均值概览
在本练习中,您将使用 K-means 的 3 分群方案来探索各列的平均值。作为"测试与学习"的探索过程的一部分,直观查看分群结果对于识别最符合业务需求的方案至关重要。
已经导入 seaborn 为 sns,以及 matplotlib.pyplot 为 plt。此外,我们已运行 K-means 的 3 分群方案,并将带有分群标签的数据集加载为 wholesale_kmeans3 DataFrame。
本练习是课程的一部分
Python 营销中的机器学习
练习说明
- 按分群标签分组并计算各列的平均值。
- 打印每个分群的各列平均值。
- 基于每个分群的各列平均值创建热力图。
- 显示图表。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# 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.___()