from lifetimes import GammaGammaFitter
ggf = GammaGammaFitter(penalizer_coef = 0)
ggf.fit(df['x'], df['Margin'])
df['clv'] = 0.0
results = {}
results_pnbd_p = {}
for i in prodname:
temp= df[df["PROD_MODEL"]==i]
ggf = GammaGammaFitter(penalizer_coef = 0)
ggf.fit(temp['x'], temp['Margin'])
pnbd = ParetoNBDFitter()
mod = pnbd.fit(temp['x'], temp['t_x'], temp['T'])
results[i] = mod.params_.values()
try:
temp['clv'] = ggf.customer_lifetime_value(mod, #the model to use to predict the number of future transactions
temp['x'], temp['t_x'], temp['T'], temp['Margin'],
time=12, # months
discount_rate=0.1)
except:
continue
print i
print results
for j in temp.index:
df.ix[j,'clv'] = temp['clv'][j]
@CamDavidsonPilon Apologies for the delay. Here it is: https://github.com/CamDavidsonPilon/lifetimes/pull/236
Maybe? That means inference elsewhere would suffer. That may be the solution I go with though. I’ll do some testing.
I’m encountering the same problem, although for me it’s for all customers with
frequency = 0
.It occurs when the GammaGammaFitter’s fitted parameter
q < 1
, causing thepopulation_mean
to be negative.