Skip to main content

Marketing Statistical Models in PyMC

Project description

PyMC-Marketing Logo


Build Test Notebook codecov Ruff docs PyPI Version PyPI - Downloads License

PyMC-Marketing: Bayesian Marketing Mix Modeling (MMM) & Customer Lifetime Value (CLV)

Marketing Analytics Tools from PyMC Labs

Unlock the power of Marketing Mix Modeling (MMM) and Customer Lifetime Value (CLV) analytics with PyMC-Marketing. This open-source marketing analytics tool empowers businesses to make smarter, data-driven decisions for maximizing ROI in marketing campaigns.


This repository is supported by PyMC Labs.

For businesses looking to integrate PyMC-Marketing into their operational framework, PyMC Labs offers expert consulting and training. Our team is proficient in state-of-the-art Bayesian modeling techniques, with a focus on Marketing Mix Models (MMMs) and Customer Lifetime Value (CLV). For more information see here.

Explore these topics further by watching our video on Bayesian Marketing Mix Models: State of the Art.

Community Resources

Quick Installation Guide for Marketing Mix Modeling (MMM) & CLV

To dive into MMM and CLV analytics, set up a specialized Python environment, marketing_env, via conda-forge:

conda create -c conda-forge -n marketing_env pymc-marketing
conda activate marketing_env

For a comprehensive installation guide, refer to the official PyMC installation documentation.

Docker

We provide a Dockerfile to build a Docker image for PyMC-Marketing so that is accessible from a Jupyter Notebook. See here for more details.

In-depth Bayesian Marketing Mix Modeling (MMM) in PyMC

Leverage our Bayesian MMM API to tailor your marketing strategies effectively. Leveraging on top of the research article Jin, Yuxue, et al. “Bayesian methods for media mix modeling with carryover and shape effects.” (2017), and extending it by integrating the expertise from core PyMC developers, our API provides:

Feature Description
Custom Priors and Likelihoods Tailor your model to your specific business needs by including domain knowledge via prior distributions.
Adstock Transformation Optimize the carry-over effects in your marketing channels.
Saturation Effects Understand the diminishing returns in media investments.
Customize adstock and saturation functions You can select from a variety of adstock and saturation functions. You can even implement your own custom functions. See documentation guide.
Time-varying Intercept Capture time-varying baseline contributions in your model (using modern and efficient Gaussian processes approximation methods). See guide notebook.
Time-varying Media Contribution Capture time-varying media efficiency in your model (using modern and efficient Gaussian processes approximation methods). See the guide notebook.
Visualization and Model Diagnostics Get a comprehensive view of your model's performance and insights.
Choose among many inference algorithms We provide the option to choose between various NUTS samplers (e.g. BlackJax, NumPyro and Nutpie). See the example notebook for more details.
Out-of-sample Predictions Forecast future marketing performance with credible intervals. Use this for simulations and scenario planning.
Budget Optimization Allocate your marketing spend efficiently across various channels for maximum ROI. See the budget optimization example notebook
Experiment Calibration Fine-tune your model based on empirical experiments for a more unified view of marketing. See the lift test integration explanation for more details. Here you can find a Case Study: Unobserved Confounders, ROAS and Lift Tests.

MMM Quickstart

import pandas as pd

from pymc_marketing.mmm import (
    GeometricAdstock,
    LogisticSaturation,
    MMM,
)

data_url = "https://raw.githubusercontent.com/pymc-labs/pymc-marketing/main/data/mmm_example.csv"
data = pd.read_csv(data_url, parse_dates=["date_week"])

mmm = MMM(
    adstock=GeometricAdstock(l_max=8),
    saturation=LogisticSaturation(),
    date_column="date_week",
    channel_columns=["x1", "x2"],
    control_columns=[
        "event_1",
        "event_2",
        "t",
    ],
    yearly_seasonality=2,
)

Initiate fitting and get a visualization of some of the outputs with:

X = data.drop("y",axis=1)
y = data["y"]
mmm.fit(X,y)
mmm.plot_components_contributions();

Once the model is fitted, we can further optimize our budget allocation as we are including diminishing returns and carry-over effects in our model.

Explore a hands-on simulated example for more insights into MMM with PyMC-Marketing.

Essential Reading for Marketing Mix Modeling (MMM)

Unlock Customer Lifetime Value (CLV) with PyMC

Understand and optimize your customer's value with our CLV models. Our API supports various types of CLV models, catering to both contractual and non-contractual settings, as well as continuous and discrete transaction modes.

Explore our detailed CLV examples using data from the lifetimes package:

Examples

Non-contractual Contractual
Continuous online purchases ad conversion time
Discrete concerts & sports events recurring subscriptions

CLV Quickstart

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from pymc_marketing import clv

data_url = "https://raw.githubusercontent.com/pymc-labs/pymc-marketing/main/data/clv_quickstart.csv"
data = pd.read_csv(data_url)
data["customer_id"] = data.index

beta_geo_model = clv.BetaGeoModel(data=data)

beta_geo_model.fit()

Once fitted, we can use the model to predict the number of future purchases for known customers, the probability that they are still alive, and get various visualizations plotted.

See the Examples section for more on this.

Why PyMC-Marketing vs other solutions?

PyMC-Marketing is and will always be free for commercial use, licensed under Apache 2.0. Developed by core developers behind the popular PyMC package and marketing experts, it provides state-of-the-art measurements and analytics for marketing teams.

Due to its open-source nature and active contributor base, new features are constantly added. Are you missing a feature or want to contribute? Fork our repository and submit a pull request. If you have any questions, feel free to open an issue.

Thanks to our contributors!

https://github.com/pymc-labs/pymc-marketing/graphs/contributors

Marketing AI Assistant: MMM-GPT with PyMC-Marketing

Not sure how to start or have questions? MMM-GPT is an AI that answers questions and provides expert advice on marketing analytics using PyMC-Marketing.

Try MMM-GPT here.

📞 Schedule a Free Consultation for MMM & CLV Strategy

Maximize your marketing ROI with a free 30-minute strategy session with our PyMC-Marketing experts. Learn how Bayesian Marketing Mix Modeling and Customer Lifetime Value analytics can boost your organization by making smarter, data-driven decisions.

We provide the following professional services:

  • Custom Models: We tailor niche marketing analytics models to fit your organization's unique needs.
  • Build Within PyMC-Marketing: Our team members are experts leveraging the capabilities of PyMC-Marketing to create robust marketing models for precise insights.
  • SLA & Coaching: Get guaranteed support levels and personalized coaching to ensure your team is well-equipped and confident in using our tools and approaches.
  • SaaS Solutions: Harness the power of our state-of-the-art software solutions to streamline your data-driven marketing initiatives.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymc_marketing-0.10.0.tar.gz (338.4 kB view details)

Uploaded Source

Built Distribution

pymc_marketing-0.10.0-py3-none-any.whl (174.6 kB view details)

Uploaded Python 3

File details

Details for the file pymc_marketing-0.10.0.tar.gz.

File metadata

  • Download URL: pymc_marketing-0.10.0.tar.gz
  • Upload date:
  • Size: 338.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pymc_marketing-0.10.0.tar.gz
Algorithm Hash digest
SHA256 0f81e997197b9f72b6915aade7bf900cf912ff64bdf84cbf4de9c65ca442b80e
MD5 1c5419431424b2a293f4bb2b501cf175
BLAKE2b-256 b1263c653c74439cfaff2a34995ae80a37df68eb97f11fe1fe7565e76c1e84bb

See more details on using hashes here.

File details

Details for the file pymc_marketing-0.10.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pymc_marketing-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 59a35061de122b995bd370b220a668ecf5bf9b8172053bf449ac7ac492e7d4f4
MD5 9fe7e5b27c22a824e83f55e55dd21273
BLAKE2b-256 f2409a0cf7c9460aa9f8e3906aa92b023238fc1242d49c784460f285fad62f82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page