GammaGammaModelIndividual#
- class pymc_marketing.clv.models.gamma_gamma.GammaGammaModelIndividual(data, model_config=None, sampler_config=None)[source]#
Gamma-Gamma model
Estimate the average monetary value of customer transactions.
The model is conditioned on the individual transaction values per user, and is based on [1], [2].
TODO: Explain assumptions of model
Check
GammaGammaModel
for an equivalent model conditioned on the average transaction value of each user.- Parameters:
data (pd.DataFrame) –
- Dataframe containing the following columns:
customer_id: Customer labels. The same value should be used for each observation
- coming from the same customer.
individual_transaction_value: Value of individual transactions.
model_config (dict, optional) – Dictionary of model prior parameters. If not provided, the model will use default priors specified in the
default_model_config
class attribute.sampler_config (dict, optional) – Dictionary of sampler parameters. Defaults to None.
Examples
Gamma-Gamma model conditioned on individual customer spend
import pymc as pm from pymc_marketing.clv import GammaGammaModelIndividual model = GammaGammaModelIndividual( data=pd.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.build_model() 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( 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"))
References
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.
Return distribution of transaction value per customer
GammaGammaModelIndividual.distribution_new_customer_spend
([...])Posterior distribution of transaction value for new customers
GammaGammaModelIndividual.expected_customer_lifetime_value
(...)Return expected customer lifetime value.
Return expected transaction value per customer
Expected transaction 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
X
default_model_config
Returns 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 .
default_sampler_config
Returns 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 .
fit_result
id
Generate a unique hash value for the model.
output_var
Returns the name of the output variable of the model.
version
y