Building a Marketing Mix Model (MMM) with Python

A step-by-step guide to building a basic Media Mix Model using Python, scikit-learn, and statsmodels to optimize marketing budget allocation.

Building a Marketing Mix Model (MMM) from Scratch

Marketing Mix Modeling (MMM) is a statistical analysis technique used to estimate the impact of various marketing tactics on sales and then forecast the impact of future sets of tactics. It helps in quantifying the effectiveness of marketing channels and optimizing budget allocation.

In this case study, we demonstrate how to build a simple yet effective MMM using Python. We released the code as an open-source project to help marketers and data scientists get started with MMM.

The Challenge

Understanding the true incremental value of marketing channels like TV, Social Media, and Search can be difficult due to:

  • Lag effects: Ads seen today might lead to a purchase next week.
  • Saturation: Doubling the budget rarely doubles the sales.
  • Seasonality: Sales fluctuate naturally throughout the year.

The Solution

We built a Python-based MMM pipeline that:

  1. Generates Synthetic Data: Simulates realistic sales and media spend.
  2. Applies Adstock Transformations: Models the decaying effect of advertising over time.
  3. Decomposes Sales: Uses regression to attribute sales to specific channels.

1. Modeling Adstock

We used a Geometric Adstock function to capture the lasting effect of advertisements. TV usually has a higher carry-over effect compared to Search.

2. Model Performance

Our model achieved an R-squared of 0.95, capturing the majority of the variance in sales.

![Actual vs Predicted Sales](/images/case-studies/mmm/sales_prediction.png)

3. Attribution & Insights

The decomposition of sales allows us to see exactly how much each channel contributed over time, separate from baseline trends and seasonality.

![Sales Decomposition](/images/case-studies/mmm/sales_decomposition.png)

The "Share of Effect" analysis reveals the relative efficiency of each channel:

![Share of Effect](/images/case-studies/mmm/share_of_effect.png)

Open Source

We believe in transparency and reproducibility. You can find the full code for this project, including data generation and modeling scripts, on our GitHub repository.

[View Code on GitHub](https://github.com/forestSKYwind/mmm-case-study)

Key Takeaways

  • TV showed a strong base effect but with high saturation.
  • Social provided efficient incremental sales but requires careful frequency management.
  • Search remains a high-intent channel with immediate impact.

Ready to build your own MMM? Check out the repo and start modeling!

Want Similar Results?

Let's discuss how these strategies can be adapted for your business.