PyMC-Marketing v1.0

In summary, PyMC-Marketing provides bayesian capabilities, as well as all its benefits, to marketing modeling. More particularly, the package allows to obtain the complete distribution of probability associated to the results, in contrast to conventional tools, which only provide point-estimate. All of this with a great flexibility and a large active community.

The 5 pillars of the Package

  1. Marketing Mix Modeling (MMM)
    • To model the impact of each marketing channel sales, in order to optimize budget allocation
  2. Customer Lifetime Value (CLV)
    • To quantify the lifetime value of your customers, i.e. the forecast of future income for each segment of customers
  3. Customer Choice Analysis (CSA)
    • To analyse clients’ preferences
  4. Bass Diffusion Model
    • To understand the adoption of your product in the market
  5. Predicted Incrementality by Experimentation
    • To measure thecausal impact of your campaigns, thanks to theanalysis ofexperiments and A/B testing

A Practical example of MMM with PyMC-Marketing

Below is a code example for running a MMM on sample data:

import numpy as np
import pandas as pd
from pymc_marketing.mmm import ( MMM, GeometricAdstock, LogisticSaturation)

# ---------------------------------------------------------------------
# 1. Data Generation
# ----------------- ----------------------------------------------------
# Sample data was generated using:
#   - date_week: the date in YYYY-MM-DD format
#   - channel_1 and 2: metrics from two marketing channels
#   - event_1 and 2: Boolean values indicating events related to the channels
#   - dayofyear: the day of the year between 1 and 365
#   - t: incremental index for each row


# ---------------------------------------------------------------------
# 2. Defining Transformations
# ---------------------------------------------------------------------
# Geometric Adstock:
#   - alpha controls the persistence of the effect
#   - l_max specifies the maximum number of weeks of delay

adstock = GeometricAdstock(l_max=8, normalize=True)

# LogisticSaturation:
#   - models diminishing returns
#   - those parameters are estimated by the model
saturation = LogisticSaturation()

# ---------------------------------------------------------------------
# 3. Marketing Mix Model definition
# ---------------------------------------------------------------------
mmm = MMM(
    date_column=date_column,
    channel_columns=channel_columns,
    target_column=target_column,
    adstock=adstock,
    saturation=saturation,

    # Optional :control variables
    # control_columns=["price", "promotion", "holiday"],

    # Optional : yearly seasonality
    yearly_seasonality=2,

    # Apply adstock first, then saturation
    adstock_first=True,

    # Sampler configuration
    sampler_config={
        "progressbar": True,
    },
)

# ---------------------------------------------------------------------
# 4. Bayesian Inference
# ---------------------------------------------------------------------
fit_result = mmm.fit(X=X, y=y, tune=500, draws=500)

Although the code is relatively brief, the generated model is well and truly complex and would have required many lines of codes with PyMC, as shown in theimage below:

The model, once adjusted, allows to analyse the contributions of the different channels and control variables (not included in the example), an overview is provided in the chart below:

Leave a Reply

Your email address will not be published. Required fields are marked *