1

谁能帮我计算 PALIVE(在校准期结束时他们仍然活着的概率。)在 Python 中?

我知道 R 有一个帕累托负二项分布函数 pnbd.PAlive(params, r, s, apha, beta) ,但在 Python 中有什么相似之处?

4

1 回答 1

1

您可以使用包中的conditional_probability_alive方法lifetimes。您需要为每个客户传递frequencyrecency和。T例如对于 BetaGeoFitter(BG/NBD 模型):

from lifetimes import BetaGeoFitter
from lifetimes.datasets import load_cdnow_summary

# load data
data = load_cdnow_summary(index_col=[0])
print(data.head())

# fit lifetimes model
bgf = BetaGeoFitter(penalizer_coef=0.0)
bgf.fit(data['frequency'], data['recency'], data['T'])
print(bgf)

# predict p_alives for customers
p_alive1 = bgf.conditional_probability_alive(2, 30.43, 38.86)
p_alive2 = bgf.conditional_probability_alive(1, 30, 30)
print(p_alive1, p_alive2)

输出:

    frequency  recency      T
ID                           
1           2    30.43  38.86
2           1     1.71  38.86
3           0     0.00  38.86
4           0     0.00  38.86
5           0     0.00  38.86
<lifetimes.BetaGeoFitter: fitted with 2357 subjects, a: 0.79, alpha: 4.41, b: 2.43, r: 0.24>
0.7266084620654866 0.753658243186767
于 2017-10-24T06:21:48.930 回答