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

Correct BetaGeo docstring example #693

Merged
merged 3 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading