计算更细粒度的 CLV
本练习将使用发票层级的更细粒度数据。该方法利用更细的明细数据,通常能给出更准确的客户终身价值(CLV)估计。请将结果与基础 CLV 模型进行比较。
pandas 和 numpy 库已分别以 pd 和 np 的名称加载。online 数据集也已为您导入。
本练习是课程的一部分
Python 营销中的机器学习
练习说明
- 按
InvoiceNo分组,并计算TotalSum列的平均值。 - 按
CustomerID和InvoiceMonth分组,并计算每位客户每月唯一发票数量的平均值。 - 将生命周期定义为 36 个月。
- 将以上三个指标相乘,得到细粒度 CLV。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Calculate average revenue per invoice
revenue_per_purchase = online.___(['___'])['TotalSum'].mean().mean()
# Calculate average number of unique invoices per customer per month
frequency_per_month = online.___(['CustomerID','InvoiceMonth'])['___'].___().mean()
# Define lifespan to 36 months
lifespan_months = 36
# Calculate granular CLV
clv_granular = ___ * frequency_per_month * lifespan_months
# Print granular CLV value
print('Average granular CLV is {:.1f} USD'.format(clv_granular))