Python port of the Meta Robyn Marketing Mix Modeling (MMM) package
Project description
Robyn Python
A Python implementation of Robyn, an experimental, automated and open-sourced Marketing Mix Modeling (MMM) code by Meta Marketing Science.
This package aims to be a feature-complete port of the original R package, providing the same automated hyperparameter optimization, ridge regression modeling, and budget allocation capabilities.
Features
- Automated Hyperparameter Optimization: Uses
Nevergradto efficiently explore adstock, saturation, and regularization parameters. - Ridge Regression: Constrained ridge regression to ensure valid coefficient signs.
- Feature Engineering: Integrated Prophet decomposition for trend, seasonality, and holiday effects.
- Multi-Objective Optimization: Optimizes for NRMSE and DECOMP.RSSD (Business Logic) to find Pareto-optimal models.
- Budget Allocation: Non-linear optimization to maximize response given budget constraints.
Installation
pip install meta-robyn-py
(Note: If not yet on PyPI, install locally)
pip install .
Quick Start
import pandas as pd
from robyn import robyn_inputs, robyn_run, robyn_outputs, robyn_allocator
# 1. Load Data
dt_input = pd.read_csv("your_data.csv")
dt_holidays = pd.read_csv("holidays.csv")
# 2. Configure Inputs
input_collect = robyn_inputs(
dt_input=dt_input,
dt_holidays=dt_holidays,
date_var="DATE",
dep_var="revenue",
dep_var_type="revenue",
prophet_vars=["trend", "season", "holiday"],
prophet_country="DE",
context_vars=["competitor_sales", "events"],
paid_media_spends=["tv_S", "facebook_S"],
paid_media_vars=["tv_S", "facebook_I"],
organic_vars=["newsletter"],
window_start="2016-11-23",
window_end="2018-08-22",
adstock="geometric"
)
# 3. Add Hyperparameters
hyperparameters = {
"tv_S_alphas": [0.5, 3], "tv_S_gammas": [0.3, 1], "tv_S_thetas": [0, 0.3],
"facebook_I_alphas": [0.5, 3], "facebook_I_gammas": [0.3, 1], "facebook_I_thetas": [0, 0.3],
"train_size": [0.5, 0.8]
# ... add for others
}
input_collect = robyn_inputs(InputCollect=input_collect, hyperparameters=hyperparameters)
# 4. Run Model
output_models = robyn_run(
InputCollect=input_collect,
iterations=2000,
trials=5,
outputs=False
)
# 5. Export Results & Clusters
output_collect = robyn_outputs(
input_collect=input_collect,
output_models=output_models,
pareto_fronts="auto",
clusters=True,
export=True
)
# 6. Budget Allocation
best_model = output_collect['clusters']['models'].iloc[0]['solID']
allocator = robyn_allocator(
input_collect=input_collect,
output_collect=output_collect,
select_model=best_model,
scenario="max_response",
channel_constr_low=0.7,
channel_constr_up=1.2
)
Comparisons with R version
This Python port has been benchmarked against the R version using standard simulation data.
| Metric | Python Port | R Reference |
|---|---|---|
| NRMSE | 0.0442 | ~0.04 - 0.06 |
| Speed | ~96 iter/s | ~50 - 100 iter/s |
See COMPARISON_REPORT.md for full details.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file meta_robyn_py-0.1.0.tar.gz.
File metadata
- Download URL: meta_robyn_py-0.1.0.tar.gz
- Upload date:
- Size: 38.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6565bd7388ce16a8e9c19e0531af4d23c16e46d9ddbfdd03df7a50f72478908
|
|
| MD5 |
f8ba89125f7da0c4b7b36b29bb6ee587
|
|
| BLAKE2b-256 |
4c4dbce83ae7d788411bc51ddf57f9bcf76682afb84788f90d7b4ae5e6270c70
|
File details
Details for the file meta_robyn_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: meta_robyn_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eac2b3a51faa43dd10c27bfae1947de34dec3431467f13c7ba9cf49a4d05be64
|
|
| MD5 |
a9debf544d9f74c1f1492d6fca22d540
|
|
| BLAKE2b-256 |
0e679b3cb0841d4876c5887def9c2550b9d06ae50d5e41b59ef7126ba3eb5e93
|