lifetimes: My clv is coming wrong. It comes negative for many customers. Can you please suggest.

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]

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (16 by maintainers)

Most upvoted comments

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 the population_mean to be negative.

<lifetimes.GammaGammaFitter: fitted with 86725 subjects, p: 15.20, q: 0.58, v: 17.24>

population_mean = v * p / (q - 1)

-631.1499946276026