{"id":13710266,"url":"https://github.com/leopoldavezac/BayesianMMM","last_synced_at":"2025-05-06T18:35:06.067Z","repository":{"id":45579560,"uuid":"364604619","full_name":"leopoldavezac/BayesianMMM","owner":"leopoldavezac","description":"(ml) - python implementation of bayesian media mix modelling with shape and carryover effect","archived":false,"fork":false,"pushed_at":"2021-12-07T12:14:09.000Z","size":2657,"stargazers_count":55,"open_issues_count":2,"forks_count":26,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-08-03T23:18:09.255Z","etag":null,"topics":["marketing","media-mix-modeling","mmm","pystan","python"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leopoldavezac.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-05T14:29:21.000Z","updated_at":"2024-02-21T14:47:44.000Z","dependencies_parsed_at":"2022-08-28T06:40:39.076Z","dependency_job_id":null,"html_url":"https://github.com/leopoldavezac/BayesianMMM","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leopoldavezac%2FBayesianMMM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leopoldavezac%2FBayesianMMM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leopoldavezac%2FBayesianMMM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leopoldavezac%2FBayesianMMM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leopoldavezac","download_url":"https://codeload.github.com/leopoldavezac/BayesianMMM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224521704,"owners_count":17325284,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["marketing","media-mix-modeling","mmm","pystan","python"],"created_at":"2024-08-02T23:00:53.721Z","updated_at":"2024-11-13T20:31:43.021Z","avatar_url":"https://github.com/leopoldavezac.png","language":"HTML","funding_links":[],"categories":["Media / Marketing Mix Models"],"sub_categories":[],"readme":"# BayesianMMM\n\nFor years scientists have tried to find the best way to model the relationship between media spends and revenue. Once this relationship modelled one can easily find the optimal media mix, a very valuable insight.\n\nHere we merely propose an implementation of one of the latest one: [bayesian methods for media mix modeling with carryover and shape effect](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/46001.pdf). \n\n------------------\n\n## Media Transformations\n\n### Carryover\n \nMore often than not we make the hypothesis that media spends have a lasting impact on sales over several days, weeks or days. Also, sometimes we make the hypothesis that the effects of media spends on sales are delayed. The carryover transformations allows to explicitly integrate those hypotheses into our model. Here we give the user the choice to use either a geo decay or adstock transformation.\n\n#### Geo Decay\n\nThe geo decay transformations allows us to model the lasting impact of marketing spends.\n\n\u003cimg src=\"docs/geo_decay.PNG\"  width=\"500\"/\u003e\n\n\u003cimg src=\"docs/geodecay_viz.png\"  width=\"500\"/\u003e\n\n\n#### Adstock\n\nThe adstock transformation allow us to model the lasting impact and delayed effect of marketing spends.\n\n\u003cimg src=\"docs/adstock.PNG\"  width=\"500\"/\u003e\n\n\u003cimg src=\"docs/adstock_viz.png\"  width=\"500\"/\u003e\n\n### Diminushing Returns (ie Shape Effect)\n\nWe also might want to make the hypothesis that the spends impact on sales follows a S curves. We can explictly integrate this hypothesis in our model using either the hill or reach transformation.\n\n#### Hill\n\n\n\u003cimg src=\"docs/hill.PNG\"  width=\"500\"/\u003e\n\n\u003cimg src=\"docs/hill_viz.png\"  width=\"500\"/\u003e\n\n\n#### Reach\n\n\u003cimg src=\"docs/reach.PNG\"  width=\"500\"/\u003e\n\n\u003cimg src=\"docs/reach_viz.png\"  width=\"500\"/\u003e\n\n\n--------------\n\n## Model\n\nPutting it all together or model can be expressed by the following formula.\n\n\n\u003cimg src=\"docs/model.PNG\"  width=\"500\"/\u003e\n\n------------\n\n## Sampling Techniques\n\nMedia mix modeling datasets are often small with less than 500 observations. This raises some issues when fitting a media mix model. To address those concerns the model's parameters are estimated using MCMC as implemented in Stan.\n\n------------\n\n## Results\n\nThis implementation output multiple results during the training phase. Those are all stored under the results folder.\n\n/console look results folder\nHere the list of those\n\n```bash\n\n    .\n    ├── ...\n    ├── results                                     # results files \n    │   ├── contributions_*.csv                     # contributions of each variables\n    │   ├── performance_*.json                      # mape on train and test set\n    │   ├── prediction_*.csv                        # prediction on train and test set\n    │   ├── plot                                    # plot based results\n    │   |    ├── carryover_*.html                   # plot of carryover effect on each media\n    │   |    ├── diminushing_returns_*.html         # plot of diminushing returns effect on each media    \n    │   |    ├── sample_*.html                      # plot of parameters' posterior\n    │   |    ├── contributions_analysis_*.html      # dashboard of media contributions   \n    |   │    └── true_vs_pred_*.html                # .plot of pred and true values     \n    │   ├── inference_machine                       # .pkl files to load fitted inference machine\n    │   └── normalizer                              # .pkl, json files to load fitted normalizer\n    └── ...\n\n\n```\n\n-------------\n\n\n## Usage\n\nIn order to use this implementation two options are avalaible from the console using the train_bayesian_mmm command or by running train.py (bayesian_mmm/train.py)\n\nBefore doing so the user must update the config file (config/train.yaml) appropriatly.\n\n-------------\n\n## Config \n\n```yaml\nDATA_SOURCE_PATH: \"./data/mmm.csv\"      #location of mmm dataset sep=\",\"\n\nEXPERIMENT_NM: \"demo\"                   #name that will be used for results\n\nMEDIA_NMS:                              #must be in same order as in mmm dataset\n  - TV\n  - radio\n  - newspaper\nCTRL_NMS: []                            #the ctrl variables to use (if any)\nDATE_NM: \"week_dt\" \nTARGET_NM: \"sales\"  \n\nNORMALIZATION:                          #how to normalize the variables\n  PREDICTORS:\n    transfo_nm: \"log\"                   #avalaible options: \"log\", None, \"sqrt\"\n    scaler_nm: \"max_abs\"                #avalaible options: \"max_abs\", \"min_max\"\n  TARGET:\n    transfo_nm: \"log\"\n    scaler_nm: \"max_abs\"\n\nMAX_LAG: 13\nCARRYOVER_TRANSFO_NM: \"geo_decay\"       #avalaible options: \"geo_decay\", \"adstock\"\nDIMINUSHING_RETURNS_TRANSFO_NM: \"reach\" #avalaible options: \"hill\", \"reach\"\n\nSAMPLING_N_ITER: 1000                   #nb of sampling iterations to run\nSAMPLING_N_PROCESSORS: 3                #nb of processors to use for sampling\n\nPARAMETER_ESTIMATOR_NM: \"median\"        #estimator to use on posterior of parameters\n\nNB_TEST_OBS: 20                         #nb of observations to use for testing\n\n```\n--------------\n\n\n## Installation\n\n```bash\n\n$ conda env create -f environment.yaml\n$ conda activate bayesian_mmm\n$ pip install -e .\n\n```\n\n\n## Further Developments\n\nGive the user the ability to:\n\n- cap gamma ctrl values\n- cap tau value\n- cap beta medias values\n- change the spend transfo order (as proposed in the paper)\n- choose media transformations at media level\n- set custom priors\n- use a multiplicative model\n\n----------------\n\n\n## References\n\n- [Bayesian methods for media mix modeling with carryover and shape effect](https://research.google/pubs/pub46001/)\n- [Challenges and Opportunities in Media Mix Modeling](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/45998.pdf)\n\n-----------------\n\n## Notes\n\nOn Windows, conda distribution must be used. pystan cannot be installed on Windows with python.\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleopoldavezac%2FBayesianMMM","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleopoldavezac%2FBayesianMMM","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleopoldavezac%2FBayesianMMM/lists"}