plot_expected_purchases_over_time#
- pymc_marketing.clv.plotting.plot_expected_purchases_over_time(model, purchase_history, customer_id_col, datetime_col, t, plot_cumulative=True, t_start_eval=None, datetime_format=None, time_unit='D', time_scaler=1, sort_purchases=True, set_index_date=False, title=None, xlabel='Time Periods', ylabel='Purchases', ax=None, t_unobserved=None, **kwargs)[source]#
Plot actual and expected purchases over time for a fitted
BetaGeoModel
orParetoNBDModel
.This function is based on the formulation on page 8 of [1]. Specifically, we take only customers who have made their first purchase before the specified number of
t
time periods, and runexpected_purchases_new_customer()
for all remaining time periods. Results can be either cumulative or incremental.Adapted from the legacy
lifetimes
library: CamDavidsonPilon/lifetimes- Parameters:
- model
A fitted
BetaGeoModel
orParetoNBDModel
.- purchase_history
DataFrame
A Pandas DataFrame containing customer_id_col and datetime_col.
- customer_id_col
str
Column in the purchases DataFrame denoting the customer_id.
- datetime_col
str
Column in the purchases DataFrame denoting datetimes purchase were made.
- t
int
Number of time units since earliest purchase to include in plot.
- plot_cumulativebool
Default: True Plot cumulative purchases over time. Set to False to plot incremental purchases.
- t_start_eval
int
, optional If testing model on unobserved data, specify number of time units in training data to add an indicator for the start of the testing period.
- datetime_format
str
, optional A string that represents the timestamp format. Useful if Pandas doesn’t recognize the provided format.
- time_unit
str
, optional Time granularity for study. Default: ‘D’ for days. Possible values listed here: https://numpy.org/devdocs/reference/arrays.datetime.html#datetime-units
- time_scaler
int
, optional Default: 1. Scales recency & T to a different time granularity. This is useful for datasets spanning many years, and running predictions in different time scales.
- sort_purchasesbool, optional
Default: True If purchase_history DataFrame is already sorted in chronological order, set to False to improve computational efficiency.
- set_index_datebool, optional
Set to True to return a dataframe with a datetime index.
- title
str
, optional Figure title
- xlabel
str
, optional Figure xlabel
- ylabel
str
, optional Figure ylabel
- ax
matplotlib.Axes
, optional A matplotlib Axes instance. Creates new axes instance by default.
- kwargs
Additional arguments to pass into the pandas.DataFrame.plot command.
- Returns:
- axes:
matplotlib.AxesSubplot
- axes:
References
[1]Fader, Peter S., Bruce G.S. Hardie, and Ka Lok Lee (2005),
A Note on Implementing the Pareto/NBD Model in MATLAB. http://brucehardie.com/notes/008/