ShiftedBetaGeoModelIndividual#
- class pymc_marketing.clv.models.shifted_beta_geo.ShiftedBetaGeoModelIndividual(data=None, *, model_config=None, sampler_config=None)[source]#
Shifted Beta Geometric model for individual customers.
Model for customer behavior in a discrete contractual setting. It assumes that:
At the end of each period, a customer has a probability
thetaof renewing the contract and1 - thetaof cancellingThe probability
thetadoes not change over time for a given customerThe probability
thetavaries across customers according to a Beta prior distribution with hyperparametersalphaandbeta.
Based on [1].
- Parameters:
- data: pd.DataFrame
DataFrame containing the following columns:
customer_id: Customer labels. There should be one unique label for each customer.t_churn: Time at which the customer cancelled the contract (starting at 0). It should equalTfor users that have not cancelled by the end of the observation period.T: Maximum observed time period (starting at 0).
- 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.
References
[1]Fader, P. S., & Hardie, B. G. (2007). How to project customer retention. Journal of Interactive Marketing, 21(1), 76-90. https://journals.sagepub.com/doi/pdf/10.1002/dir.20074
Examples
import pandas as pd import pymc as pm from pymc_extras.prior import Prior from pymc_marketing.clv import ShiftedBetaGeoModelIndividual data = pd.DataFrame({ customer_id=[0, 1, 2, 3, ...], t_churn=[1, 2, 8, 4, 8 ...], T=[8 for x in range(len(customer_id))], }) model = ShiftedBetaGeoModelIndividual( model_config={ "alpha": Prior("HalfNormal", sigma=10), "beta": Prior("HalfStudentT", nu=4, sigma=10), }, 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 how many periods in the future are existing customers likely to cancel (ignoring that some may already have cancelled) expected_churn_time = model.distribution_customer_churn_time( customer_id=[0, 1, 2, 3, ...], ) print(expected_churn_time.mean("customer_id")) # Predict churn time for 10 new customers, conditioned on data new_customers_churn_time = model.distribution_new_customer_churn_time(n=10) print(new_customers_churn_time.mean("new_customer_id"))
Methods
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 InferenceData object.
Build the model.
Create attributes for the inference data.
ShiftedBetaGeoModelIndividual.distribution_customer_churn_time(...)Sample distribution of churn time for existing customers.
ShiftedBetaGeoModelIndividual.distribution_new_customer_churn_time([...])Sample distribution of churn time for new customers.
ShiftedBetaGeoModelIndividual.distribution_new_customer_theta([...])Sample distribution of theta parameter for new customers.
ShiftedBetaGeoModelIndividual.fit([data, ...])Infer model posterior.
Compute the summary of the fit result.
ShiftedBetaGeoModelIndividual.graphviz(**kwargs)Get the graphviz representation of the model.
Create the initialization kwargs from an InferenceData object.
ShiftedBetaGeoModelIndividual.load(fname[, ...])Create a ModelBuilder instance from a file.
Create a ModelBuilder instance from an InferenceData object.
ShiftedBetaGeoModelIndividual.save(fname, ...)Save the model's inference data to a file.
Set attributes on an InferenceData object.
Get the summary table of the model.
Return a copy of the model with a thinned fit result.
Attributes
default_model_configDefault model configuration.
default_sampler_configDefault sampler configuration.
fit_resultGet the posterior fit_result.
idGenerate a unique hash value for the model.
posteriorAccess the 'posterior' attribute of the InferenceData object.
posterior_predictiveAccess the 'posterior_predictive' attribute of the InferenceData object.
predictionsAccess the 'predictions' attribute of the InferenceData object.
priorAccess the 'prior' attribute of the InferenceData object.
prior_predictiveAccess the 'prior_predictive' attribute of the InferenceData object.
versionidatasampler_configmodel_config