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, **kwargs)[source]#
Plot actual and expected purchases over time for a fitted
BetaGeoModelorParetoNBDModel.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
ttime periods, and runexpected_purchases_new_customer()for all remaining time periods. Results can be either cumulative or incremental.Adapted from the legacy
lifetimeslibrary: CamDavidsonPilon/lifetimes- Parameters:
model – A fitted
BetaGeoModelorParetoNBDModel.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_cumulative (
bool) – Default: True Plot cumulative purchases over time. Set to False to plot incremental purchases.t_start_eval (
int|None) – 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|None) – A string that represents the timestamp format. Useful if Pandas doesn’t recognize the provided format.time_unit (
str) – Time granularity for study. Default: ‘D’ for days. Possible values listed here: https://numpy.org/devdocs/reference/arrays.datetime.html#datetime-unitstime_scaler (
float|None) – 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_purchases (
bool|None) – Default: True If purchase_history DataFrame is already sorted in chronological order, set to False to improve computational efficiency.set_index_date (
bool|None) – Set to True to return a dataframe with a datetime index.xlabel (
str) – Figure xlabelylabel (
str) – Figure ylabelax (
Axes|None) – A matplotlib Axes instance. Creates new axes instance by default.kwargs – Additional arguments to pass into the pandas.DataFrame.plot command.
- Return type:
axes:
matplotlib.AxesSubplot
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/