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.
- 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
CausalImpactto measure incremental lift from specific marketing interventions.
- 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)
The core engine uses a Logistic Saturation function to model diminishing returns.
It accounts for geography-specific nuances through hierarchical priors, allowing the model to "learn" from one region to inform another.
OptiSpend/
├── app/
│ └── main.py
├── data/
│ ├── raw/
│ └── processed/
├── models/
├── src/
│ ├── train.py
│ ├── causal_analysis.py
│ └── utils.py
├── reports/
├── requirements.txt
└── README.md
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.
-
Clone the Repo:
git clone [https://github.com/yinkak/OptiSpend.git](https://github.com/yinkak/OptiSpend.git) cd OptiSpend -
Install Dependencies:
pip install -r requirements.txt
-
Launch the app:
streamlit run app/main.py
- 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.
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:
- Ensure your
venvis active. - Run the training pipeline:
python3 src/train.py
- The script will output the mmm_trace.nc file into the models/ directory, which is ignored by Git.
Developed by Yinka Kolawole – feel free to reach out via LinkedIn or open an issue for collaboration!