GammaGammaModelIndividual#
- class pymc_marketing.clv.models.gamma_gamma.GammaGammaModelIndividual(data, 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 spend values of each purchase for each customer, and is based on [1], [2].
See
GammaGammaModelfor an equivalent model conditioned on mean transaction values of repeat purchases for the customer population.- Parameters:
- data
DataFrame Dataframe containing the following columns:
customer_id: Unique customer identifierindividual_transaction_value: Monetary value of each purchase for each customer
- model_config
dict, optional Dictionary of model prior parameters. If not provided, the model will use default priors specified in the
default_model_configclass attribute.- sampler_config
dict, optional Dictionary of sampler parameters. Defaults to None.
- data
References
[1]Fader, P. S., & Hardie, B. G. (2013). “The Gamma-Gamma model of monetary value”. http://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 pymc as pm from pymc_marketing.clv import GammaGammaModelIndividual model = GammaGammaModelIndividual( data=pandas.DataFrame( { "customer_id": [0, 0, 0, 1, 1, 2, ...], "individual_transaction_value": [5.3. 5.7, 6.9, 13.5, 0.3, 19.2 ...], } ), model_config={ "p_prior": {dist: 'HalfNorm', kwargs: {}}, "q_prior": {dist: 'HalfStudentT', kwargs: {"nu": 4, "sigma": 10}}, "v_prior": {dist: 'HalfCauchy', kwargs: {}}, }, sampler_config={ "draws": 1000, "tune": 1000, "chains": 2, "cores": 2, "nuts_kwargs": {"target_accept": 0.95}, }, ) model.fit() print(model.fit_summary()) # Predict spend of customers for which we know transaction history, # conditioned on data. May include customers not included in fitting expected_customer_spend = model.expected_customer_spend( data=pandas.DataFrame( { "customer_id": [0, 0, 0, 1, 1, 2, ...], "individual_transaction_value": [5.3. 5.7, 6.9, 13.5, 0.3, 19.2 ...], } ), ) 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
GammaGammaModelIndividual.__init__(data[, ...])Initializes model configuration and sampler configuration for the model
Creates an instance of pm.Model based on provided data and model_config, and attaches it to self.
Posterior distribution of mean spend values for each customer.
GammaGammaModelIndividual.distribution_new_customer_spend([...])Posterior distribution of mean spend values for new customers.
GammaGammaModelIndividual.expected_customer_lifetime_value(...)Compute the average lifetime value for a group of one or more customers, and apply a discount rate for net present value estimations.
Expected future mean spend value per customer.
Expected mean spend value for a new customer.
GammaGammaModelIndividual.fit([fit_method])Infer model posterior
GammaGammaModelIndividual.fit_summary(**kwargs)Get all the model parameters needed to instantiate a copy of the model, not including training data.
Creates a ModelBuilder instance from a file, Loads inference data for the model.
GammaGammaModelIndividual.predict(X_pred[, ...])Uses model to predict on unseen data and return point prediction of all the samples.
Generate posterior predictive samples on unseen data.
Alias for
predict_posterior, for consistency with scikit-learn probabilistic estimators.GammaGammaModelIndividual.sample_posterior_predictive(X_pred)Sample from the model's posterior predictive distribution.
Sample from the model's prior predictive distribution.
Save the model's inference data to a file.
Set attributes on an InferenceData object.
GammaGammaModelIndividual.set_params(**params)Set all the model parameters needed to instantiate the model, not including training data.
Return a copy of the model with a thinned fit result.
Attributes
Xdefault_model_configReturns a class default config dict for model builder if no model_config is provided on class initialization Useful for understanding structure of required model_config to allow its customization by users Examples -------- >>> @classmethod >>> def default_model_config(self): >>> Return { >>> 'a' : { >>> 'loc': 7, >>> 'scale' : 3 >>> }, >>> 'b' : { >>> 'loc': 3, >>> 'scale': 5 >>> } >>> 'obs_error': 2 >>> }
default_sampler_configReturns a class default sampler dict for model builder if no sampler_config is provided on class initialization Useful for understanding structure of required sampler_config to allow its customization by users Examples -------- >>> @classmethod >>> def default_sampler_config(self): >>> Return { >>> 'draws': 1_000, >>> 'tune': 1_000, >>> 'chains': 1, >>> 'target_accept': 0.95, >>> }
fit_resultidGenerate a unique hash value for the model.
output_varReturns the name of the output variable of the model.
versiony