Skip to content

yinkak/OptiSpend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OptiSpend: Bayesian Marketing Mix Modeling & Optimization

OptiSpend is an end-to-end marketing analytics suite designed to quantify the impact of media spend across multiple geographies and channels. Using Bayesian Structural Time Series and Causal Inference, it transforms raw marketing data into actionable budget reallocations.

Key Features

  • Bayesian MMM: A hierarchical model that estimates saturation and decay (adstock) effects of media spend.
  • Budget Optimizer: Uses a custom utility function to find the "Maximum Yield" budget allocation across regions.
  • Forecasting Lab: Integrated with Facebook Prophet to predict baseline sales trends and future acquisition.
  • Causal Inference: An experimentation module using Google's CausalImpact to measure incremental lift from specific marketing interventions.

Technical Stack

  • Language: Python 3.12
  • Modeling: PyMC (Bayesian Inference), Prophet (Time-Series Forecasting)
  • Causal Analysis: CausalImpact (Bayesian Structural Time Series)
  • Frontend: Streamlit (Interactive Dashboard)
  • Optimization: Scipy.optimize (Sequential Least Squares Programming)

How it Works

1. The Model (Marketing Mix Modeling)

The core engine uses a Logistic Saturation function to model diminishing returns.

$$Contribution = \beta \cdot \frac{1 - e^{-\alpha \cdot spend}}{1 + e^{-\alpha \cdot spend}}$$

It accounts for geography-specific nuances through hierarchical priors, allowing the model to "learn" from one region to inform another.

📂 Project Structure

OptiSpend/
├── app/
│   └── main.py            
├── data/
│   ├── raw/               
│   └── processed/         
├── models/                
├── src/
│   ├── train.py           
│   ├── causal_analysis.py 
│   └── utils.py           
├── reports/               
├── requirements.txt
└── README.md

2. The Experimentation Lab

Unlike traditional models, OptiSpend includes a Causal Inference module. By defining a "Pre-Period" and "Post-Period," the system builds a synthetic control group to isolate the true incremental lift of a campaign, filtering out seasonality and market noise.

Run it Locally

  1. Clone the Repo:

    git clone [https://github.com/yinkak/OptiSpend.git](https://github.com/yinkak/OptiSpend.git)
    cd OptiSpend
  2. Install Dependencies:

    pip install -r requirements.txt
  3. Launch the app:

    streamlit run app/main.py

📈 Roadmap

  • Phase 1-3: Core MMM Engine & Optimizer
    • Bayesian hierarchical modeling with PyMC.
    • Custom utility functions for budget reallocation.
    • Interactive Streamlit dashboard for ROI visualization.
  • Phase 4: Forecasting & Experimentation
    • Integrated Prophet modules for baseline sales projection.
    • CausalImpact implementation for incremental lift analysis.
    • Automated data-snapping for weekly time-series alignment.
  • Phase 5: Cloud Deployment & Scalability
    • Deployed to Streamlit Cloud for live stakeholder access.
    • Optimized model pickling for faster load times.
    • Added API endpoints for automated weekly data ingestion.

Model Storage & GitHub Constraints

The core model output (mmm_trace.nc) is a high-dimensional Bayesian trace file approximately 538 MB in size.

Why it is not in this repository:

  • GitHub File Limits: GitHub enforces a 100 MB limit per file.
  • Git Integrity: Large binary files bloat repository size and slow down cloning for other users.
  • Reproducibility: In line with ML best practices, this project prioritizes Code-as-Infrastructure. Instead of downloading a static model, users are encouraged to generate the trace locally to ensure environment compatibility.

How to generate the model locally: If you wish to perform analysis or run the dashboard, you must generate the trace file on your local machine:

  1. Ensure your venv is active.
  2. Run the training pipeline:
    python3 src/train.py
  3. The script will output the mmm_trace.nc file into the models/ directory, which is ignored by Git.

Contact & Contributions

Developed by Yinka Kolawole – feel free to reach out via LinkedIn or open an issue for collaboration!

About

End-to-end Marketing Mix Modeling (MMM) & Causal Inference suite. Uses Bayesian hierarchical modeling (PyMC) for budget optimization and CausalImpact for incrementality testing. Features an interactive Streamlit dashboard and Prophet-backed forecasting.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors