GammaGammaModel#
- class pymc_marketing.clv.models.gamma_gamma.GammaGammaModel(*, model_config=None, sampler_config=None)[source]#
Gamma-Gamma Model for expected future monetary value.
The Gamma-Gamma model assumes expected future spend follows a Gamma distribution, and the scale of this distribution is also Gamma-distributed.
This model is conditioned on the mean value of repeat transactions for each customer, and is based on [1], [2]. Data must be summarized by frequency and monetary_value for each customer, using
clv.rfm_summary()or equivalent.See
GammaGammaModelIndividualfor an equivalent model conditioned on individual transaction values.- Parameters:
data (
DataFrame) –DataFrame containing the following columns:
customer_id: Unique customer identifiermonetary_value: Mean transaction value of repeat purchases for each customerfrequency: Number of repeat transactions observed for each customer
model_config (
dict|None) – Dictionary of model prior parameters. If not provided, the model will use default priors specified in thedefault_model_configclass attribute.sampler_config (
dict|None) – Dictionary of sampler parameters. Defaults to None.
References
[1]Fader, P. S., & Hardie, B. G. (2013). “The Gamma-Gamma model of monetary value”. https://www.brucehardie.com/notes/025/gamma_gamma.pdf
[2]Peter S. Fader, Bruce G. S. Hardie, and Ka Lok Lee (2005), “RFM and CLV: Using iso-value curves for customer base analysis”, Journal of Marketing Research, 42 (November), 415-430. https://journals.sagepub.com/doi/pdf/10.1509/jmkr.2005.42.4.415
Examples
import pandas as pd import pymc as pm from pymc_extras.prior import Prior data = pd.DataFrame( { "customer_id": [0, 1, 2, 3, ...], "monetary_value": [23.5, 19.3, 11.2, 100.5, ...], "frequency": [6, 8, 2, 1, ...], } model = GammaGammaModel( ), model_config={ "p": Prior("HalfNormal"), "q": Prior("HalfStudentT", nu=4, sigma=10), "v": Prior("HalfCauchy", beta=1), }, sampler_config={ "draws": 1000, "tune": 1000, "chains": 2, "cores": 2, "nuts_kwargs": {"target_accept": 0.95}, }, ) model.fit(data=data) print(model.fit_summary()) # Predict spend of customers for which we know transaction history, conditioned on data. expected_customer_spend = ( model.expected_customer_spend( data=pandas.DataFrame( { "customer_id": [0, 1, 2, 3, ...], "monetary_value": [23.5, 19.3, 11.2, 100.5, ...], "frequency": [6, 8, 2, 1, ...], } ), ), ) print(expected_customer_spend.mean("customer_id")) # Predict spend of 10 new customers, conditioned on data new_customer_spend = model.expected_new_customer_spend(n=10) print(new_customer_spend.mean("new_customer_id"))
Methods
GammaGammaModel.__init__(*[, model_config, ...])Initialize model configuration and sampler configuration for the model.
Convert the model configuration and sampler configuration from the attributes to keyword arguments.
Build the model from the DataTree object.
Build the model.
Build the
fit_datagroup stored alongside the posterior.Create attributes for the inference data.
Posterior distribution of mean spend values for each customer.
Posterior distribution of mean spend values for new customers.
Compute the average lifetime value for a group of one or more customers.
Compute the expected future mean spend value per customer.
Compute the expected mean spend value for a new customer.
GammaGammaModel.fit([data, method, ...])Infer the model posterior.
GammaGammaModel.fit_summary(**kwargs)Compute the summary of the fit result.
GammaGammaModel.graphviz(**kwargs)Get the graphviz representation of the model.
Create the model configuration and sampler configuration from the DataTree to keyword arguments.
GammaGammaModel.load(fname[, check])Create a ModelBuilder instance from a file.
GammaGammaModel.load_from_idata(idata[, check])Create a ModelBuilder instance from a DataTree object.
Perform transformation on the model after sampling.
GammaGammaModel.save(fname, **kwargs)Save the model's inference data to a file.
GammaGammaModel.set_idata_attrs([idata])Set attributes on a DataTree object.
GammaGammaModel.table(**model_table_kwargs)Get the summary table of the model.
GammaGammaModel.thin_fit_result(keep_every)Return a copy of the model with a thinned fit result.
Attributes
Default model configuration.
Default sampler configuration.
Get the posterior fit_result.
Generate a unique hash value for the model.
Access the 'posterior' group of the DataTree.
Access the 'posterior_predictive' group of the DataTree.
Access the 'predictions' group of the DataTree.
Access the 'prior' group of the DataTree.
Access the 'prior_predictive' group of the DataTree.