RFM讲解——Plotly Python
我正在kaggle中学习RFM分析,发现了一些有趣的东西。这个用于 RFM 分析的“树形图”结果不是由绘图生成的,不知何故,每个类别的框的大小是由“rfm_坐标”确定的,我不知道它来自哪里。我尝试交换 rfm_坐标值,例如:冠军与风险交换,描述尚未更改,但框的大小没有变化。那么这个预制的“树形图”图表来自哪里?
rfm_coordinates = {"Champions": [3, 5, 0.8, 1],
"Loyal Customers": [3, 5, 0.4, 0.8],
"Cannot lose them": [4, 5, 0, 0.4],
"At-Risk": [2, 4, 0, 0.4],
"Hibernating": [0, 2, 0, 0.4],
"About To Sleep": [0, 2, 0.4, 0.6],
"Promising": [0, 1, 0.6, 0.8],
"New Customers": [0, 1, 0.8, 1],
"Potential Loyalists": [1, 3, 0.6, 1],
"Need Attention": [2, 3, 0.4, 0.6]}
fig, ax = plt.subplots(figsize = (19, 15))
ax.set_xlim([0, 5])
ax.set_ylim([0, 5])
plt.rcParams["axes.facecolor"] = "white"
palette = ["#282828", "#04621B", "#971194", "#F1480F", "#4C00FF",
"#FF007B", "#9736FF", "#8992F3", "#B29800", "#80004C"]
for key, color in zip(rfm_coordinates.keys(), palette[:10]):
coordinates = rfm_coordinates[key]
ymin, ymax, xmin, xmax = coordinates[0], coordinates[1], coordinates[2], coordinates[3]
ax.axhspan(ymin = ymin, ymax = ymax, xmin = xmin, xmax = xmax, facecolor = color)
users = rfm_table[rfm_table.Segment == key].shape[0]
users_percentage = (rfm_table[rfm_table.Segment == key].shape[0] / rfm_table.shape[0]) * 100
avg_monetary = rfm_table[rfm_table.Segment == key]["Monetary"].mean()
user_txt = "\n\nTotal Users: " + str(users) + "(" + str(round(users_percentage, 2)) + "%)"
monetary_txt = "\n\n\n\nAverage Monetary: " + str(round(avg_monetary, 2))
x = 5 * (xmin + xmax) / 2
y = (ymin + ymax) / 2
plt.text(x = x, y = y, s = key, ha = "center", va = "center", fontsize = 18, color = "white", fontweight = "bold")
plt.text(x = x, y = y, s = user_txt, ha = "center", va = "center", fontsize = 14, color = "white")
plt.text(x = x, y = y, s = monetary_txt, ha = "center", va = "center", fontsize = 14, color = "white")
ax.set_xlabel("Recency Score")
ax.set_ylabel("Frequency Score")
sns.despine(left = True, bottom = True)
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
qcut()
rfm_coordinates
来移动在图中生成图形,
rfm_coordinates
已定义文本使用文本 >
数据源
matplotlib 代码
qcut()
rfm_coordinates
generate figure in plotly
rfm_coordinates
being defineddata sourcing
matplotlib code