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 GammaGammaModel for an equivalent model conditioned on mean transaction values of repeat purchases for the customer population.

Parameters:
dataDataFrame

Dataframe containing the following columns:

  • customer_id: Unique customer identifier

  • individual_transaction_value: Monetary value of each purchase for each customer

model_configdict, optional

Dictionary of model prior parameters. If not provided, the model will use default priors specified in the default_model_config class attribute.

sampler_configdict, optional

Dictionary of sampler parameters. Defaults to None.

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": {dist: 'HalfNorm', kwargs: {}},
        "q": {dist: 'HalfStudentT', kwargs: {"nu": 4, "sigma": 10}},
        "v": {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[, ...])

Initialize model configuration and sampler configuration for the model.

GammaGammaModelIndividual.attrs_to_init_kwargs(attrs)

Convert the model configuration and sampler configuration from the attributes to keyword arguments.

GammaGammaModelIndividual.build_from_idata(idata)

Build model from the InferenceData object.

GammaGammaModelIndividual.build_model()

Build the model.

GammaGammaModelIndividual.create_fit_data(X, y)

Create the fit_data group based on the input data.

GammaGammaModelIndividual.create_idata_attrs()

Create attributes for the inference data.

GammaGammaModelIndividual.distribution_customer_spend(data)

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.

GammaGammaModelIndividual.expected_customer_spend(data)

Compute the expected future mean spend value per customer.

GammaGammaModelIndividual.expected_new_customer_spend()

Compute the expected mean spend value for a new customer.

GammaGammaModelIndividual.fit([method, ...])

Infer model posterior.

GammaGammaModelIndividual.fit_summary(**kwargs)

Compute the summary of the fit result.

GammaGammaModelIndividual.graphviz(**kwargs)

Get the graphviz representation of the model.

GammaGammaModelIndividual.load(fname)

Create a ModelBuilder instance from a file.

GammaGammaModelIndividual.load_from_idata(idata)

Create a ModelBuilder instance from an InferenceData object.

GammaGammaModelIndividual.post_sample_model_transformation()

Perform transformation on the model after sampling.

GammaGammaModelIndividual.predict([X, ...])

Use a model to predict on unseen data and return point prediction of all the samples.

GammaGammaModelIndividual.predict_posterior([...])

Generate posterior predictive samples on unseen data.

GammaGammaModelIndividual.predict_proba([X, ...])

Alias for predict_posterior, for consistency with scikit-learn probabilistic estimators.

GammaGammaModelIndividual.sample_posterior_predictive([...])

Sample from the model's posterior predictive distribution.

GammaGammaModelIndividual.sample_prior_predictive([...])

Sample from the model's prior predictive distribution.

GammaGammaModelIndividual.save(fname)

Save the model's inference data to a file.

GammaGammaModelIndividual.set_idata_attrs([idata])

Set attributes on an InferenceData object.

GammaGammaModelIndividual.thin_fit_result(...)

Return a copy of the model with a thinned fit result.

Attributes

X

default_model_config

Default model configuration.

default_sampler_config

Default sampler configuration.

fit_result

Get the posterior fit_result.

id

Generate a unique hash value for the model.

output_var

Output variable of the model.

posterior

posterior_predictive

predictions

prior

prior_predictive

version

y