Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot_period_transactions failed for BetaGeoBetaBinomFitter #354

Open
hmikelee opened this issue Feb 5, 2020 · 3 comments
Open

plot_period_transactions failed for BetaGeoBetaBinomFitter #354

hmikelee opened this issue Feb 5, 2020 · 3 comments

Comments

@hmikelee
Copy link

hmikelee commented Feb 5, 2020

Dear Sir,

While testing BG/BB models, I came across the following error when calling plot_period_transactions to verify the fitting results

TypeError: unsupported operand type(s) for +: 'int' and 'list'

Traceback below:

TypeError                                 Traceback (most recent call last)
<ipython-input-30-4d245b7ff070> in <module>()
      2 bbf.fit(summary_monthly['frequency'], summary_monthly['recency'], summary_monthly['n_periods'])
      3 print(bbf)
----> 4 plot_period_transactions(bbf)
      5 
      6 for period in summary_monthly['n_periods'].unique():

~/anaconda3/lib/python3.6/site-packages/lifetimes/plotting.py in plot_period_transactions(model, max_frequency, title, xlabel, ylabel, **kwargs)
     59 
     60     n = model.data.shape[0]
---> 61     simulated_data = model.generate_new_data(size=n)
     62 
     63     model_counts = pd.DataFrame(model.data["frequency"].value_counts().sort_index().iloc[:max_frequency])

~/anaconda3/lib/python3.6/site-packages/lifetimes/fitters/beta_geo_beta_binom_fitter.py in <lambda>(size)
    167         self.generate_new_data = lambda size=1: beta_geometric_beta_binom_model(
    168             # Making a large array replicating n by n_custs having n.
--> 169             np.array(sum([n_] * n_cust for (n_, n_cust) in zip(n_periods, weights))),
    170             *self._unload_params("alpha", "beta", "gamma", "delta"),
    171             size=size

TypeError: unsupported operand type(s) for +: 'int' and 'list'

BetaGeoBetaBinomFitter.fit went ok

I am attaching the screenshot of the notebook below

image

@SUBHAMILA
Copy link

code with error : self.generate_new_data = lambda size=1: beta_geometric_beta_binom_model( # Making a large array replicating n by n_custs having n. np.array(sum([n_] * n_cust for (n_, n_cust) in zip(n_periods, weights))), *self._unload_params("alpha", "beta", "gamma", "delta"), size=size )
i think the following changes may solve your problem .
try doing this :
you get that error because one is integer value and other is list.

try this :

self.generate_new_data = lambda size=1: beta_geometric_beta_binom_model( # Making a large array replicating n by n_custs having n. np.array(sum([n_] * sum(n_cust) for (n_, n_cust) in zip(n_periods, weights))), *self._unload_params("alpha", "beta", "gamma", "delta"), size=size )

@psygo
Copy link
Collaborator

psygo commented Feb 7, 2020

@SUBHAMILA, please use three backticks (`) for code blocks, otherwise that is illegible.

@Trollgeir
Copy link

code with error : self.generate_new_data = lambda size=1: beta_geometric_beta_binom_model( # Making a large array replicating n by n_custs having n. np.array(sum([n_] * n_cust for (n_, n_cust) in zip(n_periods, weights))), *self._unload_params("alpha", "beta", "gamma", "delta"), size=size )
i think the following changes may solve your problem .
try doing this :
you get that error because one is integer value and other is list.

try this :

self.generate_new_data = lambda size=1: beta_geometric_beta_binom_model( # Making a large array replicating n by n_custs having n. np.array(sum([n_] * sum(n_cust) for (n_, n_cust) in zip(n_periods, weights))), *self._unload_params("alpha", "beta", "gamma", "delta"), size=size )

This did not work.

This did though:

The solution that worked was to modify row 169 in beta_geo_beta_binom_fitter.py from np.array(sum([n_] * n_cust for (n_, n_cust) in zip(n_periods, weights))) to np.array(sum([[n_] * >n_cust for (n_, n_cust) in zip(n_periods, weights)], []))

Credits to @cereusperuv (#259 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants