如何使用Python中的lifeties包获取客户生命周期的期望值

2024-04-28 05:27:00 发布

您现在位置:Python中文网/ 问答频道 /正文

python包的生命周期使用BG/NBD方法,这与R包BTYD相同。在

在R论文中,我们可以在给定的时间范围内估计任何新获得的客户的客户生命周期(CLV)包。但是,我在python中找不到等价的函数。在

我能找到的所有信息似乎都是以过去的频率和最近的条件概率来估计CLV。有人有这方面的经验吗?在


Tags: 方法函数信息客户时间经验概率条件
1条回答
网友
1楼 · 发布于 2024-04-28 05:27:00

是的。从documentation Estimating customer lifetime value using the Gamma-Gamma model开始。在

步骤1:适合BG模型

确保您有frequency, monetary_value格式的数据,例如:

from lifetimes.datasets import load_cdnow_summary_data_with_monetary_value

data = load_cdnow_summary_data_with_monetary_value()
data.head()
             frequency  recency      T  monetary_value
customer_id
1                    2    30.43  38.86           22.35
2                    1     1.71  38.86           11.77
6                    7    29.43  38.86           73.74
7                    1     5.00  38.86           11.77
9                    2    35.71  38.86           25.55

然后拟合BG模型:

^{pr2}$

第2步:拟合伽马-伽马模型

# Filter out customers who did not return 
returning_customers_summary = data[data['frequency']>0]

from lifetimes import GammaGammaFitter

ggf = GammaGammaFitter(penalizer_coef = 0)
ggf.fit(returning_customers_summary['frequency'],
        returning_customers_summary['monetary_value'])

第三步:估算寿命值

在这里,您将调用fitted gamma gamma函数,并使用先前拟合的BetaGeoFilter和一组客户数据,其中包含{frequency,recency,T,以及他们的花费/事件(monetary_value)}(以天为单位),以及一个以个月为单位的时间线和一个折扣率。在

print(ggf.customer_lifetime_value(
    bgf, #the model to use to predict the number of future transactions
    summary_with_money_value['frequency'],
    summary_with_money_value['recency'],
    summary_with_money_value['T'],
    summary_with_money_value['monetary_value'],
    time=12, # months
    discount_rate=0.01 # monthly discount rate ~ 12.7% annually
    ).head(10))
"""
customer_id
1      140.096211
2       18.943467
3       38.180574
4       38.180574
5       38.180574
6     1003.868107
7       28.109683
8       38.180574
9      167.418216
10      38.180574
Name: clv, dtype: float64
"""

相关问题 更多 >