谁能帮助我在Python中计算PALIVE(在校准期结束时它们仍然存在的概率)?
我知道R具有帕累托负二项式分布function pnbd.PAlive(params, r, s, apha, beta)
但是与Python有什么相似之处?
最佳答案
您可以使用conditional_probability_alive
包中的lifetimes
方法。您需要为每个客户传递frequency
,recency
和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
关于python - R中的pnbd.PAlive等Python中的PALIVE语法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46857571/