Skip to content

Commit

Permalink
Correct BetaGeo docstring example (#693)
Browse files Browse the repository at this point in the history
* fix example in docstring

* change docstring
  • Loading branch information
wd60622 authored and twiecki committed Sep 10, 2024
1 parent 9784c5f commit 0e31efa
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions pymc_marketing/clv/models/beta_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class BetaGeoModel(CLVModel):
Methods below are adapted from the BetaGeoFitter class from the lifetimes package
(see https://github.com/CamDavidsonPilon/lifetimes/).
Parameters
----------
data: pd.DataFrame
Expand Down Expand Up @@ -97,19 +96,28 @@ class BetaGeoModel(CLVModel):
model.fit()
print(model.fit_summary())
# Estimating the expected number of purchases for a randomly chosen
# individual in a future time period of length t
Predicting the customer-specific number of purchases for a future time
interval of length t given their previous frequency, recency, and T
.. code-block:: python
future_t = [2, 5, 7, 10]
expected_num_purchases = model.expected_num_purchases(
t=[2, 5, 7, 10],
t=future_t,
customer_id=data["customer_id"],
frequency=data["frequenc"y],
recency=data["recency"],
T=data["T"],
)
# Predicting the customer-specific number of purchases for a future
# time interval of length t given their previous frequency and recency
Estimating the expected number of purchases for a randomly chosen
individual in a future time period of length t
.. code-block:: python
expected_num_purchases_new_customer = model.expected_num_purchases_new_customer(
t=[5, 5, 5, 5],
frequency=[5, 2, 1, 8],
recency=[7, 4, 2.5, 11],
T=[10, 8, 10, 22],
t=future_t,
)
References
Expand Down Expand Up @@ -255,6 +263,22 @@ def expected_num_purchases(
\frac{\alpha + T}{\alpha + T + t}
\right)^{r + x}
}
Parameters
----------
customer_id : np.ndarray | pd.Series
Customer identifier. Not required to be from data.
t : np.ndarray | pd.Series | TensorVariable
Time interval for which to predict the number of future purchases.
frequency : np.ndarray | pd.Series | TensorVariable
Number of repeat purchases.
recency : np.ndarray | pd.Series | TensorVariable
Time between the first and the last purchase.
Returns
-------
xr.DataArray
Expected number of purchases in the next time interval of length :math:`t`.
"""
t = np.asarray(t)
if t.size != 1:
Expand Down Expand Up @@ -340,6 +364,15 @@ def expected_num_purchases_new_customer(
\text{hyp2f1}\left(r, b; a + b - 1; \frac{t}{\alpha + t}\right)
\right]
Parameters
----------
t : np.ndarray | pd.Series
Time interval for which to predict the number of future purchases.
Returns
-------
xr.DataArray
Expected number of purchases in the next time interval of length :math:`t`.
"""
t = np.asarray(t)
if t.size != 1:
Expand Down

0 comments on commit 0e31efa

Please sign in to comment.