lifetimes
lifetimes copied to clipboard
gamma_gamma_fitter.py:66: RuntimeWarning: divide by zero encountered in log
The documentation describes frequency
as the number of time periods containing repeat purchases. I'm converting transactional SQL data to RFM so frequency in my case is count(distinct date(date_trans)) - 1 as frequency
. This results in a zero for all customers who only made a single purchase. When feeding these samples into the GammaGammaFitter, at https://github.com/CamDavidsonPilon/lifetimes/blob/master/lifetimes/fitters/gamma_gamma_fitter.py#L66 log(frequency)
is calculated which causes a divide by zero runtime exception for those zero entries.
What is the correct fix for this?
- Remove all samples with no repeat purchases from the GammaGammaFitter data set.
- Change the definition of
frequency
for GammaGammaFitter to include the first purchase by adding 1 to the value. - Something else?
Hey @jhurliman, the correct answer is 1. The implemented model only allows for repeat purchases. The docs here do the filtering you suggest, too.
@CamDavidsonPilon I am running into same RuntimeWarning: divide by zero encountered in log
even though my data is filtered for frequency > 0
.
returning_customers_summary = summary_data[summary_data['frequency'] > 0]
returning_customers_summary[['monetary_value', 'frequency']].corr()
ggf = lifetimes.GammaGammaFitter(penalizer_coef = 0.01)
ggf.fit(returning_customers_summary['frequency'], returning_customers_summary['monetary_value'])
summary_data['CLV_1year'] = ggf.customer_lifetime_value(
transaction_prediction_model=model,
frequency=summary_data['frequency'],
recency=summary_data['recency'],
T=summary_data['T'],
monetary_value=summary_data['monetary_value'],
time=12,
discount_rate=0
).round(0)
Any thoughts?