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 or ParetoNBDModel.

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 run expected_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 or ParetoNBDModel.

purchase_historyDataFrame

A Pandas DataFrame containing customer_id_col and datetime_col.

customer_id_colstr

Column in the purchases DataFrame denoting the customer_id.

datetime_colstr

Column in the purchases DataFrame denoting datetimes purchase were made.

tint

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_evalint, 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_formatstr, optional

A string that represents the timestamp format. Useful if Pandas doesn’t recognize the provided format.

time_unitstr, optional

Time granularity for study. Default: ‘D’ for days. Possible values listed here: https://numpy.org/devdocs/reference/arrays.datetime.html#datetime-units

time_scalerint, 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.

titlestr, optional

Figure title

xlabelstr, optional

Figure xlabel

ylabelstr, optional

Figure ylabel

axmatplotlib.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

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/