Skip to main content

Marketing Statistical Models in PyMC

Project description

PyMC-Marketing

Build codecov docs Code style: black PyPI Version License

Bayesian Media Mix Models (MMMs) in PyMC

In this package we provide an API for a Bayesian media mix model (MMM) specification following Jin, Yuxue, et al. “Bayesian methods for media mix modeling with carryover and shape effects.” (2017).. Concretely, given a time series target variable $y_{t}$ (e.g. sales on conversions), media variiables $x_{m, t}$ (e.g. impressions, clicks or costs) and a set of control covariates $z_{c, t}$ (e.g. holidays, special events) we consider a linear model of the form

$$ y_{t} = \alpha + \sum_{m=1}^{M}\beta_{m}f(x_{m, t}) + \sum_{c=1}^{C}\gamma_{c}z_{c, t} + \varepsilon_{t}, $$

where $\alpha$ is the intercept, $f$ is a media transformation function and $\varepsilon_{t}$ is the error therm which we assume is normally distributed. The function $f$ encodes the contribution of media on the target variable. Typically we consider two types of transformation: adstock (carry-over) and saturation effects.

Here you can find a simulated example:

  1. First, we describe the data genaration process of a simulated dataset.
  2. Next, we describe how to specify and fit a media mix model (as described above) using the pymc-marketing MMM's API.
  3. Finally, we describe the model results: channel constribution and ROAS estimation. We also show how the model recovers the parameters from the data generation process step.

References:


Bayesian CLVs in PyMC

Customer Lifetime Value models is another important class of models. There are many different types of CLV models and it can be helpful to conceptualise them as fitting in a 2-dimensional grid as below. An excellent set of introduction slides to CLV's is provided in Probability Models for Customer-Base Analysis by Fader & Hardie (2009).

Examples

Non-contractual Contractual
Continuous Buying groceries Audible
Discrete Cinema ticket Monthly or yearly subscriptions

To explain further:

  • Contractual: In contractual settings a customer has a contract which continues to be active until it is explicitly cancelled. Therefore in contractual settings, customer churn events are observed.

  • Non-contractual: In non-contractual settings, there is no ongoing contract that a customer has with a company. Instead, purchases can be ad hoc and churn events are unobserved.

  • Discrete: Here, purchases are made at discrete points in time. This obviously depends upon the timescale that we are working on, but typically a relevant time period would be a month or year. However it could be more granualar than this - think of taking the 2nd of 4 inter-city train journeys offered per day.

  • Continuous: In the continuous-time domain, purchases can be made at any point within a firms opening hours. For online ordering this could be any point within a 24 hour cycle, or purchases in physical stores could be made at any point during the trading day.

In the documentation we provide some examples on how to use the CLV API. We use the data from the lifetimes package to illustrate the models.


Local Development

  1. Create conda environment. For example:
conda create -n pymc_marketing_env
  1. Activate environment.
conda activate pymc_marketing_env
  1. Install pymc_marketing package:
make init
  1. To run tests:
make test
  1. To check code style:
make check_lint
  1. Set pre-commit hooks (Optional):
pre-commit install

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.0.4.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

pymc_marketing-0.0.4-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

File details

Details for the file pymc-marketing-0.0.4.tar.gz.

File metadata

  • Download URL: pymc-marketing-0.0.4.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for pymc-marketing-0.0.4.tar.gz
Algorithm Hash digest
SHA256 9d936e0c1144a73406645c71919e6c0fdaaffda6220be25da680f8de224e67bb
MD5 dda035d93836fc7be83f2f87ba54d6a2
BLAKE2b-256 72bf2e2e95e6e3b9c68ba939b95ae6af8511998fc999456a7845993cd1d7caf1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymc_marketing-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e77b80506abcc774a61900ecac5b263a1cbc8e8baf2dc597171f0c463103372d
MD5 a607110d377c78607cfdebaa1bb84075
BLAKE2b-256 f17db2a5aad55b14a548afdb6bc6f0289ed199d56a784d927a0c99dda397a4d9

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