{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cd57497d-15d1-4945-82a8-212bc15f12e7",
   "metadata": {},
   "source": [
    "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ourownstory/neural_prophet/blob/master/tutorials/feature-use/lagged_covariates_energy_ercot.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "85717c9a-58a3-4861-a5b9-1ae5939a584d",
   "metadata": {},
   "source": [
    "# Using Lagged Covariates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "bd356b90-c426-4fe0-9be5-00d43e1392f8",
   "metadata": {},
   "outputs": [],
   "source": [
    "if 'google.colab' in str(get_ipython()):\n",
    "    !pip install git+https://github.com/ourownstory/neural_prophet.git # may take a while\n",
    "    #!pip install neuralprophet # much faster, but may not have the latest upgrades/bugfixes\n",
    "    \n",
    "import pandas as pd\n",
    "from neuralprophet import NeuralProphet, set_log_level\n",
    "set_log_level(\"ERROR\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "093b8646-9c7f-4a8f-a9b6-d1ab87d9f49d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ds</th>\n",
       "      <th>COAST</th>\n",
       "      <th>EAST</th>\n",
       "      <th>FAR_WEST</th>\n",
       "      <th>NORTH</th>\n",
       "      <th>NORTH_C</th>\n",
       "      <th>SOUTHERN</th>\n",
       "      <th>SOUTH_C</th>\n",
       "      <th>WEST</th>\n",
       "      <th>y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2004-01-01 01:00:00</td>\n",
       "      <td>7225.09</td>\n",
       "      <td>877.79</td>\n",
       "      <td>1044.89</td>\n",
       "      <td>745.79</td>\n",
       "      <td>7124.21</td>\n",
       "      <td>1660.45</td>\n",
       "      <td>3639.12</td>\n",
       "      <td>654.61</td>\n",
       "      <td>22971.94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2004-01-01 02:00:00</td>\n",
       "      <td>6994.25</td>\n",
       "      <td>850.75</td>\n",
       "      <td>1032.04</td>\n",
       "      <td>721.34</td>\n",
       "      <td>6854.58</td>\n",
       "      <td>1603.52</td>\n",
       "      <td>3495.16</td>\n",
       "      <td>639.88</td>\n",
       "      <td>22191.52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2004-01-01 03:00:00</td>\n",
       "      <td>6717.42</td>\n",
       "      <td>831.63</td>\n",
       "      <td>1021.10</td>\n",
       "      <td>699.70</td>\n",
       "      <td>6639.48</td>\n",
       "      <td>1527.99</td>\n",
       "      <td>3322.70</td>\n",
       "      <td>623.42</td>\n",
       "      <td>21383.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2004-01-01 04:00:00</td>\n",
       "      <td>6554.27</td>\n",
       "      <td>823.56</td>\n",
       "      <td>1015.41</td>\n",
       "      <td>691.84</td>\n",
       "      <td>6492.39</td>\n",
       "      <td>1473.89</td>\n",
       "      <td>3201.72</td>\n",
       "      <td>613.49</td>\n",
       "      <td>20866.56</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2004-01-01 05:00:00</td>\n",
       "      <td>6511.19</td>\n",
       "      <td>823.38</td>\n",
       "      <td>1009.74</td>\n",
       "      <td>686.76</td>\n",
       "      <td>6452.26</td>\n",
       "      <td>1462.76</td>\n",
       "      <td>3163.74</td>\n",
       "      <td>613.32</td>\n",
       "      <td>20723.15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    ds    COAST    EAST  FAR_WEST   NORTH  NORTH_C  SOUTHERN  \\\n",
       "0  2004-01-01 01:00:00  7225.09  877.79   1044.89  745.79  7124.21   1660.45   \n",
       "1  2004-01-01 02:00:00  6994.25  850.75   1032.04  721.34  6854.58   1603.52   \n",
       "2  2004-01-01 03:00:00  6717.42  831.63   1021.10  699.70  6639.48   1527.99   \n",
       "3  2004-01-01 04:00:00  6554.27  823.56   1015.41  691.84  6492.39   1473.89   \n",
       "4  2004-01-01 05:00:00  6511.19  823.38   1009.74  686.76  6452.26   1462.76   \n",
       "\n",
       "   SOUTH_C    WEST         y  \n",
       "0  3639.12  654.61  22971.94  \n",
       "1  3495.16  639.88  22191.52  \n",
       "2  3322.70  623.42  21383.44  \n",
       "3  3201.72  613.49  20866.56  \n",
       "4  3163.74  613.32  20723.15  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_location = \"https://raw.githubusercontent.com/ourownstory/neuralprophet-data/main/datasets/\"\n",
    "df_ercot = pd.read_csv(data_location + \"energy/ERCOT_load.csv\")\n",
    "df_ercot.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9ad1dedc-f4d7-4dc2-b596-bb2778efad47",
   "metadata": {},
   "outputs": [],
   "source": [
    "regions = list(df_ercot)[1:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "3d262c58-cb4d-48f0-a758-0665e35dbd1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_ercot['y'].isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "efcfd48f-b0ae-44a5-aba6-a5498b80edf7",
   "metadata": {},
   "source": [
    "## Baseline Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f8952210-6d14-4086-a2cc-92fd2d347757",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\"ds\": df_ercot[\"ds\"], \"y\": df_ercot[\"y\"]})\n",
    "m = NeuralProphet(\n",
    "    learning_rate=0.1, \n",
    ")\n",
    "metrics = m.fit(df, freq=\"H\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "34bcb110-2842-4c34-b555-40521349e2d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 170244 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 55620 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 120324 characters]",
      "text/plain": [
       "<Figure size 720x1080 with 5 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "# comp = m.plot_components(forecast)\n",
    "param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "14d78adb-1c03-4bd0-8d6b-c6e515afb503",
   "metadata": {
    "tags": []
   },
   "source": [
    "##  3-steps ahead AR Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "158f7be8-7910-4f2b-9246-aec0369736d4",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\"ds\": df_ercot[\"ds\"], \"y\": df_ercot[\"y\"]})\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=3,\n",
    "    n_lags=3,\n",
    "    learning_rate=0.1,\n",
    ")\n",
    "m = m.highlight_nth_step_ahead_of_each_forecast(3)\n",
    "metrics = m.fit(df, freq=\"H\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7545eb63-d40d-42b4-9936-6d6c75054bd3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 157660 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 72776 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 128732 characters]",
      "text/plain": [
       "<Figure size 720x1296 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "# comp = m.plot_components(forecast[-7*24:])\n",
    "param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e13b2d24-3932-41be-9136-d9b976fb2b34",
   "metadata": {},
   "source": [
    "## 3-steps ahead AR and Lagged Regressors Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "776c7bbd-7284-4444-830d-9e397df3233a",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = df_ercot\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=3,\n",
    "    n_lags=3,\n",
    "    learning_rate= 0.1,\n",
    ")\n",
    "m = m.add_lagged_regressor(names=regions) #, only_last_value=True)\n",
    "m.highlight_nth_step_ahead_of_each_forecast(3)\n",
    "metrics = m.fit(df, freq=\"H\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "b37276fc-071c-45bd-8180-59b840124866",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 157756 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 71992 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 271260 characters]",
      "text/plain": [
       "<Figure size 720x3024 with 14 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "# comp = m.plot_components(forecast[-7*24:])\n",
    "param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ba46a962-20c7-4b15-a124-5b6c1e906e96",
   "metadata": {},
   "source": [
    "## 24-steps ahead Long AR Model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "32934451-eb9a-4cc4-82b8-82c6b826f683",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\"ds\": df_ercot[\"ds\"], \"y\": df_ercot[\"y\"]})\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=24,\n",
    "    n_lags=7*24,\n",
    "    learning_rate=0.1,\n",
    ")\n",
    "m.highlight_nth_step_ahead_of_each_forecast(24)\n",
    "metrics = m.fit(df, freq=\"H\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "d8453104-9854-4ff3-9eab-90389ec16c61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 157940 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 72504 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 129304 characters]",
      "text/plain": [
       "<Figure size 720x1296 with 6 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "# comp = m.plot_components(forecast[-7*24:])\n",
    "param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "abe2c42f-5861-46e9-800b-bd9a2f34700d",
   "metadata": {},
   "source": [
    "## 24-steps ahead Long AR Model with last observation of Lagged Regressors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "1419ab13-ee2a-45af-b15c-2397ce21d912",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = df_ercot\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=24,\n",
    "    n_lags=7*24,\n",
    "    learning_rate=0.1,\n",
    ")\n",
    "m = m.add_lagged_regressor(names=regions, only_last_value=True)\n",
    "m.highlight_nth_step_ahead_of_each_forecast(24)\n",
    "metrics = m.fit(df, freq=\"H\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "20abd00f-301d-46ab-8c44-556653d44a89",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING - (py.warnings._showwarnmsg) - /home/tabletop/github/neural_prophet/neuralprophet/forecaster.py:1243: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead.  To get a de-fragmented frame, use `newframe = frame.copy()`\n",
      "  df_forecast[\"{}{}\".format(comp, forecast_lag)] = yhat\n",
      "\n",
      "WARNING - (py.warnings._showwarnmsg) - /home/tabletop/github/neural_prophet/neuralprophet/forecaster.py:1251: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead.  To get a de-fragmented frame, use `newframe = frame.copy()`\n",
      "  df_forecast[comp] = yhat\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 157220 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 71260 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 152804 characters]",
      "text/plain": [
       "<Figure size 720x1512 with 7 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "# comp = m.plot_components(forecast[-7*24:])\n",
    "param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7547a817-2644-4dc6-9ec0-8578b08b7309",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 24-steps ahead AR Model with full Lagged Regressors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "486ac004-447b-4c62-a4f6-46543a69bd0e",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = df_ercot\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=24,\n",
    "    n_lags=24,\n",
    "    learning_rate=0.01,\n",
    ")\n",
    "m = m.add_lagged_regressor(names=regions)\n",
    "m.highlight_nth_step_ahead_of_each_forecast(24)\n",
    "metrics = m.fit(df, freq=\"H\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "81014f27-ddc3-4fee-8b23-7cdbad48e9ef",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING - (py.warnings._showwarnmsg) - /home/tabletop/github/neural_prophet/neuralprophet/forecaster.py:1243: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead.  To get a de-fragmented frame, use `newframe = frame.copy()`\n",
      "  df_forecast[\"{}{}\".format(comp, forecast_lag)] = yhat\n",
      "\n",
      "WARNING - (py.warnings._showwarnmsg) - /home/tabletop/github/neural_prophet/neuralprophet/forecaster.py:1251: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead.  To get a de-fragmented frame, use `newframe = frame.copy()`\n",
      "  df_forecast[comp] = yhat\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 157096 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 72172 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 271056 characters]",
      "text/plain": [
       "<Figure size 720x3024 with 14 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "# comp = m.plot_components(forecast[-7*24:])\n",
    "param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f27b1dff-4d68-44a6-8d56-9f65ffc0ea98",
   "metadata": {},
   "source": [
    "## 24-steps ahead Neural Model with Long AR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "9e49e54d-bcc7-42d4-a06e-0431fd0480b2",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = pd.DataFrame({\"ds\": df_ercot[\"ds\"], \"y\": df_ercot[\"y\"]})\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=24,\n",
    "    n_lags=7*24,\n",
    "    learning_rate=0.01,\n",
    "    num_hidden_layers=1,\n",
    "    d_hidden=16,\n",
    ")\n",
    "m = m.highlight_nth_step_ahead_of_each_forecast(24)\n",
    "metrics = m.fit(df, freq=\"H\")\n",
    "\n",
    "# metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ee300bdc-db7f-44fd-acff-b66781520634",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 159768 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 73076 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 154856 characters]",
      "text/plain": [
       "<Figure size 720x1080 with 5 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "comp = m.plot_components(forecast[-7*24:])\n",
    "# param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3dfe499-8739-4fd7-8ce2-9986df899128",
   "metadata": {},
   "source": [
    "## 24-steps ahead Neural Model with Long AR and Lagged Regressors"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "3f248fa7-fa9a-48f5-aaaf-7df6aaa91271",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "                                                                                                                                                  \r"
     ]
    }
   ],
   "source": [
    "df = df_ercot\n",
    "m = NeuralProphet(\n",
    "    n_forecasts=24,\n",
    "    n_lags=7*24,\n",
    "    learning_rate=0.01,\n",
    "    num_hidden_layers=1,\n",
    "    d_hidden=16,\n",
    ")\n",
    "m = m.add_lagged_regressor(names=regions)#, only_last_value=True)\n",
    "m = m.highlight_nth_step_ahead_of_each_forecast(24)\n",
    "metrics = m.fit(df, freq=\"H\")\n",
    "\n",
    "# metrics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "39856f0e-284f-4491-88c2-c222e72ddd4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING - (py.warnings._showwarnmsg) - /home/tabletop/github/neural_prophet/neuralprophet/forecaster.py:1243: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead.  To get a de-fragmented frame, use `newframe = frame.copy()`\n",
      "  df_forecast[\"{}{}\".format(comp, forecast_lag)] = yhat\n",
      "\n",
      "WARNING - (py.warnings._showwarnmsg) - /home/tabletop/github/neural_prophet/neuralprophet/forecaster.py:1251: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead.  To get a de-fragmented frame, use `newframe = frame.copy()`\n",
      "  df_forecast[comp] = yhat\n",
      "\n"
     ]
    },
    {
     "data": {
      "image/png": "[encoded data, 155108 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 71912 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 348164 characters]",
      "text/plain": [
       "<Figure size 720x2808 with 13 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "forecast = m.predict(df)\n",
    "# fig = m.plot(forecast)\n",
    "fig1 = m.plot(forecast[-365*24:])\n",
    "fig2 = m.plot(forecast[-7*24:])\n",
    "comp = m.plot_components(forecast[-7*24:])\n",
    "# param = m.plot_parameters()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a1989cbb-b2b9-4b8a-b825-b9501f37be22",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "np-dev",
   "language": "python",
   "name": "np-dev"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
