ColtAllen / btyd

Buy Till You Die and Customer Lifetime Value statistical models in Python.
https://btyd.readthedocs.io/
Apache License 2.0
112 stars 8 forks source link

btyd.fitters.BaseFitter._fit() got multiple values for keyword argument 'bounds' #87

Open Username159 opened 1 year ago

Username159 commented 1 year ago

Hi,

I want to pass custom bound values to the scipy.optimize.minimuze function in the GammaGammaFitter.fit() function, but I get the following error: btyd.fitters.BaseFitter._fit() got multiple values for keyword argument 'bounds'.

A small, simplified example to replicate this error would be:

from btyd import BetaGeoFitter
from btyd import GammaGammaFitter

from lifetimes.datasets import load_cdnow_summary_data_with_monetary_value

df_parsed = load_cdnow_summary_data_with_monetary_value()
returning_customers_summary = df_parsed[df_parsed["frequency"] != 0]
model = BetaGeoFitter()
model.fit(
    frequency=df_parsed["frequency"], 
    recency=df_parsed["recency"], 
    T=df_parsed["T"]
)
print(model.summary)

gg_model = GammaGammaFitter(penalizer_coef=1e-2)
gg_model.fit(
    frequency=returning_customers_summary["frequency"],
    monetary_value=returning_customers_summary["monetary_value"],
    bounds=((None, None), (0.00996, None), (None, None))
)

I need this feature to avoid problems with GammaGammaFitter.conditional_expected_average_profit() and GammaGammaFitter.customer_lifetime_value(). For my data I need a higher penalizer_coef which results in a q smaller than 1. Which then leads to negative CLV outputs. When I set q_constraint = True (meaning bounds=((None, None), (0.0, None), (None, None))) , I get q=1.0 as a parameter, which leads to nan values in GammaGammaFitter.conditional_expected_average_profit() and GammaGammaFitter.customer_lifetime_value(), so I want to "force" q to be bigger than 1.0 with custom bounds.

ColtAllen commented 1 year ago

Hey @Username159,

GammaGammaFitter.fit() is a pre-fork legacy function from lifetimes; development ceased on that library 3 years ago.

I no longer maintain btyd because I've transitioned these efforts to the pymc-marketing project. I advise you to pip install and use the Gamma-Gamma model in that library instead:

https://github.com/pymc-labs/pymc-marketing

Here's a comparative notebook:

https://www.pymc-marketing.io/en/latest/notebooks/clv/gamma_gamma.html