{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(data_container)=\n", "# Using shared variables (`Data` container adaptation)\n", "\n", ":::{post} Dec 16, 2021\n", ":tags: posterior predictive, shared data \n", ":category: beginner\n", ":author: Juan Martin Loyola, Kavya Jaiswal, Oriol Abril\n", ":::" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on PyMC3 v3.11.4\n" ] } ], "source": [ "import arviz as az\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import pandas as pd\n", "import pymc3 as pm\n", "\n", "from numpy.random import default_rng\n", "\n", "print(f\"Running on PyMC3 v{pm.__version__}\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "%config InlineBackend.figure_format = 'retina'\n", "RANDOM_SEED = 8927\n", "rng = default_rng(RANDOM_SEED)\n", "az.style.use(\"arviz-darkgrid\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Data class\n", "\n", "The {class}`pymc.Data` container class wraps the theano shared variable class and lets the model be aware of its inputs and outputs. This allows one to change the value of an observed variable to predict or refit on new data. All variables of this class must be declared inside a model context and specify a name for them.\n", "\n", "In the following example, this is demonstrated with fictional temperature observations." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Berlin | \n", "San Marino | \n", "Paris | \n", "
|---|---|---|---|
| date | \n", "\n", " | \n", " | \n", " |
| 2020-05-01 | \n", "14.777358 | \n", "18.512741 | \n", "14.971224 | \n", "
| 2020-05-02 | \n", "16.325659 | \n", "16.938007 | \n", "15.612136 | \n", "
| 2020-05-03 | \n", "14.429030 | \n", "17.901775 | \n", "15.835249 | \n", "
| 2020-05-04 | \n", "15.668249 | \n", "18.389226 | \n", "16.027941 | \n", "
| 2020-05-05 | \n", "16.145381 | \n", "16.044643 | \n", "17.492074 | \n", "