ColtAllen / btyd

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

ggf.customer_lifetime_value produces NaN clv #57

Closed littlesweet1129 closed 2 years ago

littlesweet1129 commented 2 years ago

Hi there, I successfully fitted a modified beta geo model as well as a gamma gamma model. However, when I use the customer_lifetime_value function from the gg model, all CLV are NaN.

DISCOUNT_a = 0.06                # annual discount rate
LIFE = 12                        # lifetime expected for the customers in months

discount_m = (1 + DISCOUNT_a)**(1/12) - 1     # monthly discount rate

clv = ggf.customer_lifetime_value(
        transaction_prediction_model = bgf,  
        frequency = df_rftv["frequency"],  
        recency = df_rftv["recency"],  
        T = df_rftv["T"],  
        monetary_value = df_rftv["monetary_value"],  
        time = LIFE,    
        freq = "D",                          
        discount_rate = discount_m)
ColtAllen commented 2 years ago

Hey @littlesweet1129,

Passing in Panda series as arguments can lead to unstable behavior because many of the internal methods in the legacy fitters module expect numpy arrays. Try making the following changes to your code:

clv = ggf.customer_lifetime_value(
        transaction_prediction_model = bgf,  
        frequency = df_rftv["frequency"].values,  
        recency = df_rftv["recency"].values,  
        T = df_rftv["T"].values,  
        monetary_value = df_rftv["monetary_value"].values,  
        time = LIFE,    
        freq = "D",                          
        discount_rate = discount_m)

It's a good practice to always use the df['column'].values convention with all of the legacy Fitter models. The Model module I'm currently building as a replacement will not have this issue because the entire dataframe is provided as an argument instead of the separate array components.