Skip to content

Commit

Permalink
Implement ParetoNBD with covariates
Browse files Browse the repository at this point in the history
Co-authored-by: Colt Allen <10178857+coltallen@users.noreply.github.com>
  • Loading branch information
ricardoV94 and ColtAllen committed Mar 15, 2024
1 parent 3e92610 commit db06d52
Show file tree
Hide file tree
Showing 4 changed files with 870 additions and 318 deletions.
3 changes: 2 additions & 1 deletion pymc_marketing/clv/distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ def sim_data(lam, mu, T):
dropout_time = rng.exponential(scale=1 / mu)
wait = rng.exponential(scale=1 / lam)

while t + wait < min(dropout_time, T):
final_t = min(dropout_time, T)
while (t + wait) < final_t:

Check warning on line 324 in pymc_marketing/clv/distributions.py

View check run for this annotation

Codecov / codecov/patch

pymc_marketing/clv/distributions.py#L323-L324

Added lines #L323 - L324 were not covered by tests
t += wait
n += 1
wait = rng.exponential(scale=1 / lam)
Expand Down
17 changes: 9 additions & 8 deletions pymc_marketing/clv/models/beta_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,18 @@ def _distribution_new_customers(
alpha = pm.HalfFlat("alpha")
r = pm.HalfFlat("r")

# This is the shape with fit_method="map"
if self.fit_result.dims == {"chain": 1, "draw": 1}:
shape_kwargs = {"shape": 1000}
else:
shape_kwargs = {}
fit_result = self.fit_result
if fit_result.sizes["chain"] == 1 and fit_result.sizes["draw"] == 1:

Check warning on line 356 in pymc_marketing/clv/models/beta_geo.py

View check run for this annotation

Codecov / codecov/patch

pymc_marketing/clv/models/beta_geo.py#L355-L356

Added lines #L355 - L356 were not covered by tests
# For map fit add a dummy draw dimension
fit_result = self.fit_result.squeeze("draw").expand_dims(

Check warning on line 358 in pymc_marketing/clv/models/beta_geo.py

View check run for this annotation

Codecov / codecov/patch

pymc_marketing/clv/models/beta_geo.py#L358

Added line #L358 was not covered by tests
draw=range(1000)
)

pm.Beta("population_dropout", alpha=a, beta=b, **shape_kwargs)
pm.Gamma("population_purchase_rate", alpha=r, beta=alpha, **shape_kwargs)
pm.Beta("population_dropout", alpha=a, beta=b)
pm.Gamma("population_purchase_rate", alpha=r, beta=alpha)

Check warning on line 363 in pymc_marketing/clv/models/beta_geo.py

View check run for this annotation

Codecov / codecov/patch

pymc_marketing/clv/models/beta_geo.py#L362-L363

Added lines #L362 - L363 were not covered by tests

return pm.sample_posterior_predictive(
self.fit_result,
fit_result,
var_names=var_names,
random_seed=random_seed,
).posterior_predictive
Expand Down
Loading

0 comments on commit db06d52

Please sign in to comment.