plot_expected_purchases_ppc#

pymc_marketing.clv.plotting.plot_expected_purchases_ppc(model, ppc='posterior', max_purchases=10, samples=1000, random_seed=45, ax=None, plot_type='hist', **kwargs)[source]#

Plot a prior or posterior predictive check for the customer purchase frequency distribution.

ParetoNBDModel, BetaGeoBetaBinomModel, BetaGeoModel and ModifiedBetaGeoModel are supported.

Adapted from legacy lifetimes library: CamDavidsonPilon/lifetimes

Parameters:
modelCLVModel

A built CLV model is required for prior predictive checks, and a fitted model for posterior predictive checks.

ppcstr, optional

Type of predictive check to perform. Options are ‘prior’ or ‘posterior’; defaults to ‘posterior’.

max_purchasesint, optional

Cutoff for bars of purchase counts to plot. Only used when plot_type is ‘hist’. Default is 10.

samplesint, optional

Number of samples to draw for prior predictive checks. This is not used for posterior predictive checks.

random_seedint, optional

Random seed to fix sampling results

axmatplotlib.Axes or sequence of matplotlib.Axes, optional

A matplotlib Axes instance, or a pair of Axes when plot_type is ‘ecdf’. Creates new axes instance(s) by default.

plot_typestr, optional

Type of plot to produce. Options are ‘hist’ for a bar chart of estimated vs observed purchase counts, or ‘ecdf’ for an ECDF plot with a 95% simultaneous confidence band and a companion difference plot. Defaults to ‘hist’.

**kwargs

Additional arguments to pass into the pandas.DataFrame.plot command when plot_type is ‘hist’. When plot_type is ‘ecdf’, num_trials and confidence_level can be passed to control the confidence band.

Returns:
axesmatplotlib.AxesSubplot, or tuple of two matplotlib.AxesSubplot when plot_type is ‘ecdf’

Notes

The confidence band of the ‘ecdf’ plot assumes a continuous reference CDF, which does not hold for integer purchase counts, so its coverage is only approximately the nominal level. It also assumes that CDF is known rather than estimated, so it warns when the predictive samples behind it are too few relative to the number of customers.