計算更細層的 CLV
在這個情境中,你會使用發票層級的較細粒度資料。這種做法能運用更細的資料,並提供更佳的顧客終身價值估計。請務必將結果與基本 CLV 模型的結果做比較。
pandas 與 numpy 函式庫已分別以 pd 與 np 名稱載入。online 資料集也已為你匯入。
本練習屬於課程
Python 的行銷機器學習
練習說明
- 以
InvoiceNo進行分組,並計算TotalSum欄位的平均值。 - 以
CustomerID與InvoiceMonth進行分組,並計算每位顧客每月唯一發票數的平均值。 - 將 lifespan 設為 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))