Skip to content

Omnichannel Media Mix Modelling (MMM) Lightweight Python Pipeline

Self-contained Python pipeline for media mix modelling. Includes geometric Adstock decay, Hill function diminishing returns, and Ridge regression spend attribution.

By Gordon Geraghty·MIT Licence·Updated: 21 August 2026·ADVANCED·GitHub Mirror ↗

Triangulating MMM with Last-Click Attribution

Attribution platforms over-attribute conversions to bottom-funnel channels while under-reporting upper-funnel influence. Media mix modelling evaluates macro spend variations over time, providing a privacy-safe complement to platform-reported metrics.

Implementation Code & Script

Adstock & Hill Transformation Enginemmm_pipeline.pypython

Python functions for computing geometric carryover decay and non-linear diminishing returns saturation.

import numpy as np
import pandas as pd
from sklearn.linear_model import Ridge

def geometric_adstock(spend_series: np.ndarray, decay_rate: float = 0.6) -> np.ndarray:
    """Computes carryover effect across successive weeks."""
    adstocked = np.zeros_like(spend_series, dtype=float)
    adstocked[0] = spend_series[0]
    for t in range(1, len(spend_series)):
        adstocked[t] = spend_series[t] + decay_rate * adstocked[t-1]
    return adstocked

def hill_diminishing_returns(adstocked_spend: np.ndarray, K: float, S: float = 2.0) -> np.ndarray:
    """Models saturation curve where K is half-saturation spend."""
    return (adstocked_spend ** S) / (adstocked_spend ** S + K ** S)

def fit_mmm_model(X_transformed: np.ndarray, y_revenue: np.ndarray, alpha: float = 1.0):
    """Fits regularized Ridge regression to estimate channel coefficients."""
    model = Ridge(alpha=alpha, positive=True)
    model.fit(X_transformed, y_revenue)
    return model

How to cite and attribute this tool

MIT Licence

This resource is free, open and un-gated under the MIT Open Source Licence. You are encouraged to use, integrate and cite it with attribution:

Geraghty, G. (2026). Omnichannel Media Mix Modelling (MMM) Lightweight Python Pipeline. Gordon Geraghty Resources Hub. https://gordongeraghty.com/resources/performance-media/lightweight-mmm-pipeline
BibTeX Format
@misc{geraghty_lightweight_mmm_pipeline,
  author = {Geraghty, Gordon},
  title = {Omnichannel Media Mix Modelling (MMM) Lightweight Python Pipeline},
  year = {2026},
  url = {https://gordongeraghty.com/resources/performance-media/lightweight-mmm-pipeline},
  note = {Head of Performance, Empire Amplify}
}

Changelog & Version History

  • v1.0.0Initial release of lightweight Python MMM pipeline with Adstock and Hill transformations.