{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(mmm_allocation_assessment)=\n", "# Budget Allocation Risk Assessment with PyMC-Marketing\n", "\n", "This notebook is centered around evaluating the risks tied to different budget allocations across various marketing channels. You'll discover how to create an optimal budget allocation that aligns with your specific risk tolerance. This knowledge will empower you to make well-informed decisions regarding your budget distribution.\n", "\n", "## Prerequisite Knowledge\n", "The notebook assumes the reader has knowledge of the essential functionalities of PyMC-Marketing. If one is unfamiliar, the [\"MMM Example Notebook\"](https://www.pymc-marketing.io/en/stable/notebooks/mmm/mmm_example.html) serves as an excellent starting point, offering a comprehensive introduction to media mix models in this context.\n", "\n", "## Expected Outcomes \n", "Upon completion of this notebook, readers will acquire a comprehensive understanding of how to evaluate the risks associated with various budget allocations and how to develop an optimal budget allocation based on specified risk tolerance criteria.\n", "\n", "## Preliminary Setup \n", "Consistent with previous notebooks in the PyMC-Marketing series, this document relies on a specific set of libraries. Below are the necessary imports required for executing the code snippets presented hereafter." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "OMP: Info #276: omp_set_nested routine deprecated, please use omp_set_max_active_levels instead.\n", "/Users/carlostrujillo/Documents/GitHub/pymc-marketing/pymc_marketing/mmm/multidimensional.py:72: FutureWarning: This functionality is experimental and subject to change. If you encounter any issues or have suggestions, please raise them at: https://github.com/pymc-labs/pymc-marketing/issues/new\n", " warnings.warn(warning_msg, FutureWarning, stacklevel=1)\n", "/var/folders/f0/rbz8xs8s17n3k3f_ccp31bvh0000gn/T/ipykernel_37952/251008383.py:9: UserWarning: The pymc_marketing.mmm.builders module is experimental and its API may change without warning.\n", " from pymc_marketing.mmm.builders.yaml import build_mmm_from_yaml\n" ] } ], "source": [ "import warnings\n", "\n", "import arviz as az\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "\n", "from pymc_marketing.mmm.budget_optimizer import optimizer_xarray_builder\n", "from pymc_marketing.mmm.builders.yaml import build_mmm_from_yaml\n", "from pymc_marketing.mmm.multidimensional import (\n", " MultiDimensionalBudgetOptimizerWrapper,\n", ")\n", "from pymc_marketing.paths import data_dir\n", "\n", "warnings.filterwarnings(\"ignore\")\n", "\n", "az.style.use(\"arviz-darkgrid\")\n", "plt.rcParams[\"figure.figsize\"] = [12, 7]\n", "plt.rcParams[\"figure.dpi\"] = 100\n", "\n", "%load_ext autoreload\n", "%autoreload 2\n", "%config InlineBackend.figure_format = \"retina\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The expectation is that a model has already been trained using the functionalities provided in prior versions of the PyMC-Marketing library. Thus, the data generation and training processes will be replicated in a different notebook. Those unfamiliar with these procedures are advised to refer to the [\"MMM Example Notebook.\"](https://www.pymc-marketing.io/en/stable/notebooks/mmm/mmm_example.html)\n", "\n", "## Loading a Pre-Trained Model\n", "To utilize a saved model, load it into a new instance of the MMM class using the load method below." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | date | \n", "y | \n", "x1 | \n", "x2 | \n", "event_1 | \n", "event_2 | \n", "dayofyear | \n", "t | \n", "geo | \n", "
---|---|---|---|---|---|---|---|---|---|
0 | \n", "2018-04-02 | \n", "3984.662237 | \n", "159.290009 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "92 | \n", "0 | \n", "geo_a | \n", "
1 | \n", "2018-04-09 | \n", "3762.871794 | \n", "56.194238 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "99 | \n", "1 | \n", "geo_a | \n", "
2 | \n", "2018-04-16 | \n", "4466.967388 | \n", "146.200133 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "106 | \n", "2 | \n", "geo_a | \n", "
3 | \n", "2018-04-23 | \n", "3864.219373 | \n", "35.699276 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "113 | \n", "3 | \n", "geo_a | \n", "
4 | \n", "2018-04-30 | \n", "4441.625278 | \n", "193.372577 | \n", "0.0 | \n", "0.0 | \n", "0.0 | \n", "120 | \n", "4 | \n", "geo_a | \n", "