PyMC Marketing#

Unlock the power of marketing analytics with PyMC-Marketing – the open source solution for smarter decision-making. Media mix modeling and customer lifetime value modules allow businesses to make data-driven decisions about their marketing campaigns. Optimize your marketing strategy and unlock the full potential of your customer data.

Installation#

Install and activate an environment (e.g. marketing_env) with the pymc-marketing package from conda-forge. It may look something like the following:

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

See the official PyMC installation guide if more detail is needed.

Quickstart#

Create a new Jupyter notebook with either JupyterLab or VS Code.

JupyterLab Notebook#

After installing the pymc-marketing package (see above), run the following with marketing_env activated:

mamba install -c conda-forge jupyterlab
jupyter lab

VS Code Notebook#

After installing the pymc-marketing package (see above), run the following with marketing_env activated:

mamba install -c conda-forge ipykernel

Start VS Code and ensure that the “Jupyter” extension is installed. Press Ctrl + Shift + P and type “Python: Select Interpreter”. Ensure that marketing_env is selected. Press Ctrl + Shift + P and type “Create: New Jupyter Notebook”.

MMM Quickstart#

import pandas as pd
from pymc_marketing import mmm


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

)
mmm = DelayedSaturatedMMM(
    date_column="date_week",
    channel_columns=["x1", "x2"],
    control_columns=[
        "event_1",
        "event_2",
        "t",
        "sin_order_1",
        "cos_order_1",
        "sin_order_2",
        "cos_order_2",
    ],
    adstock_max_lag=8,
    yearly_seasonality=2,
)

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

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

See the Example notebooks section for examples of further types of plot you can get, as well as introspect the results of the fitting.

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/datasets/clv_quickstart.csv"
data = pd.read_csv(data_url)

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.

📞 Schedule a Consultation#

Unlock your potential with a free 30-minute strategy session with our PyMC experts. Discover how open source solutions and pymc-marketing can elevate your media-mix models and customer lifetime value analyses. Boost your career and organization by making smarter, data-driven decisions. Don’t wait—claim your complimentary session today and lead the way in marketing and data science innovation.

Support#

This repository is supported by PyMC Labs.

For companies that want to use PyMC-Marketing in production, PyMC Labs is available for consulting and training. We can help you build and deploy your models in production. We have experience with cutting edge Bayesian modelling techniques which we have applied to a range of business domains including marketing analytics.

PyMC Labs logo PyMC Labs logo