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

如何使用Python中的lifetimes包获得客户生命周期的期望值,python,lifetime,lifetimes-python,Python,Lifetime,Lifetimes Python,python包的生命周期使用BG/NBD方法,这与R包BTYD相同 在R论文中,我们可以在给定特定时间范围的任何新获得的客户上估计客户生命周期(CLV)包。但是,我无法在python中找到等效函数 似乎我能找到的所有信息都是根据过去的频率和最近度作为条件概率来估计CLV。有人有过这方面的经验吗?有。从 步骤1:安装BG模型 确保您有频率、货币价值格式的数据,例如: from lifetimes.datasets import load_cdnow_summary_data_with_moneta

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

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

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

有。从

步骤1:安装BG模型 确保您有
频率、货币价值
格式的数据,例如:

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型号:

from lifetimes import BetaGeoFitter

# similar API to scikit-learn and lifelines.
bgf = BetaGeoFitter(penalizer_coef=0.0)
bgf.fit(data['frequency'], data['recency'], data['T'])
步骤2:拟合Gamma模型 步骤3:估计寿命值 在这里,您使用先前拟合的BetaGeoFilter和一组客户数据调用拟合的gamma gamma函数,这些数据包括{frequency,Recenty,T及其支出/事件(
monetary\u 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
"""
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
"""