You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ML-For-Beginners/TimeSeries/2-ARIMA/solution/notebook.ipynb

750 lines
785 KiB

4 years ago
{
"cells": [
{
"source": [
"# Time series forecasting with ARIMA\n",
"\n",
"In this notebook, we demonstrate how to:\n",
4 years ago
"- prepare time series data for training an ARIMA time series forecasting model\n",
4 years ago
"- implement a simple ARIMA model to forecast the next HORIZON steps ahead (time *t+1* through *t+HORIZON*) in the time series\n",
"- evaluate the model \n",
"\n",
"\n",
"The data in this example is taken from the GEFCom2014 forecasting competition<sup>1</sup>. It consists of 3 years of hourly electricity load and temperature values between 2012 and 2014. The task is to forecast future values of electricity load. In this example, we show how to forecast one time step ahead, using historical load data only.\n",
"\n",
"<sup>1</sup>Tao Hong, Pierre Pinson, Shu Fan, Hamidreza Zareipour, Alberto Troccoli and Rob J. Hyndman, \"Probabilistic energy forecasting: Global Energy Forecasting Competition 2014 and beyond\", International Journal of Forecasting, vol.32, no.3, pp 896-913, July-September, 2016."
4 years ago
],
"cell_type": "markdown",
"metadata": {}
},
{
"cell_type": "code",
4 years ago
"execution_count": 1,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: statsmodels in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.12.2)\n",
"Requirement already satisfied: numpy>=1.15 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from statsmodels) (1.19.2)\n",
"Requirement already satisfied: pandas>=0.21 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from statsmodels) (1.1.2)\n",
4 years ago
"Requirement already satisfied: scipy>=1.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from statsmodels) (1.4.1)\n",
"Requirement already satisfied: patsy>=0.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from statsmodels) (0.5.1)\n",
4 years ago
"Requirement already satisfied: pytz>=2017.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas>=0.21->statsmodels) (2019.1)\n",
4 years ago
"Requirement already satisfied: python-dateutil>=2.7.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from pandas>=0.21->statsmodels) (2.8.0)\n",
"Requirement already satisfied: six in /Users/jenlooper/Library/Python/3.7/lib/python/site-packages (from patsy>=0.5->statsmodels) (1.12.0)\n",
4 years ago
"\u001b[33mWARNING: You are using pip version 20.2.3; however, version 21.1.1 is available.\n",
"You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -m pip install --upgrade pip' command.\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"pip install statsmodels"
4 years ago
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 2,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import warnings\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import datetime as dt\n",
"import math\n",
"\n",
"from pandas.plotting import autocorrelation_plot\n",
"from statsmodels.tsa.statespace.sarimax import SARIMAX\n",
"from sklearn.preprocessing import MinMaxScaler\n",
"from common.utils import load_data, mape\n",
"from IPython.display import Image\n",
"\n",
"%matplotlib inline\n",
"pd.options.display.float_format = '{:,.2f}'.format\n",
"np.set_printoptions(precision=2)\n",
"warnings.filterwarnings(\"ignore\") # specify to ignore warning messages\n"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 3,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" load\n",
"2012-01-01 00:00:00 2,698.00\n",
"2012-01-01 01:00:00 2,558.00\n",
"2012-01-01 02:00:00 2,444.00\n",
"2012-01-01 03:00:00 2,402.00\n",
"2012-01-01 04:00:00 2,403.00\n",
"2012-01-01 05:00:00 2,453.00\n",
"2012-01-01 06:00:00 2,560.00\n",
"2012-01-01 07:00:00 2,719.00\n",
"2012-01-01 08:00:00 2,916.00\n",
"2012-01-01 09:00:00 3,105.00"
],
"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>load</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2012-01-01 00:00:00</th>\n <td>2,698.00</td>\n </tr>\n <tr>\n <th>2012-01-01 01:00:00</th>\n <td>2,558.00</td>\n </tr>\n <tr>\n <th>2012-01-01 02:00:00</th>\n <td>2,444.00</td>\n </tr>\n <tr>\n <th>2012-01-01 03:00:00</th>\n <td>2,402.00</td>\n </tr>\n <tr>\n <th>2012-01-01 04:00:00</th>\n <td>2,403.00</td>\n </tr>\n <tr>\n <th>2012-01-01 05:00:00</th>\n <td>2,453.00</td>\n </tr>\n <tr>\n <th>2012-01-01 06:00:00</th>\n <td>2,560.00</td>\n </tr>\n <tr>\n <th>2012-01-01 07:00:00</th>\n <td>2,719.00</td>\n </tr>\n <tr>\n <th>2012-01-01 08:00:00</th>\n <td>2,916.00</td>\n </tr>\n <tr>\n <th>2012-01-01 09:00:00</th>\n <td>3,105.00</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
4 years ago
"execution_count": 3
4 years ago
}
],
4 years ago
"source": [
"energy = load_data('./data')[['load']]\n",
"energy.head(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot all available load data (January 2012 to Dec 2014)"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 4,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1080x576 with 1 Axes>",
4 years ago
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"465.658661pt\" version=\"1.1\" viewBox=\"0 0 904.55375 465.658661\" width=\"904.55375pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 465.658661 \nL 904.55375 465.658661 \nL 904.55375 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 60.35375 398.88 \nL 897.35375 398.88 \nL 897.35375 7.2 \nL 60.35375 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m5a98fc59ac\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"60.35375\" xlink:href=\"#m5a98fc59ac\" y=\"398.88\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- Jan -->\n <defs>\n <path d=\"M 9.8125 72.90625 \nL 19.671875 72.90625 \nL 19.671875 5.078125 \nQ 19.671875 -8.109375 14.671875 -14.0625 \nQ 9.671875 -20.015625 -1.421875 -20.015625 \nL -5.171875 -20.015625 \nL -5.171875 -11.71875 \nL -2.09375 -11.71875 \nQ 4.4375 -11.71875 7.125 -8.046875 \nQ 9.8125 -4.390625 9.8125 5.078125 \nz\n\" id=\"DejaVuSans-74\"/>\n <path d=\"M 34.28125 27.484375 \nQ 23.390625 27.484375 19.1875 25 \nQ 14.984375 22.515625 14.984375 16.5 \nQ 14.984375 11.71875 18.140625 8.90625 \nQ 21.296875 6.109375 26.703125 6.109375 \nQ 34.1875 6.109375 38.703125 11.40625 \nQ 43.21875 16.703125 43.21875 25.484375 \nL 43.21875 27.484375 \nz\nM 52.203125 31.203125 \nL 52.203125 0 \nL 43.21875 0 \nL 43.21875 8.296875 \nQ 40.140625 3.328125 35.546875 0.953125 \nQ 30.953125 -1.421875 24.3125 -1.421875 \nQ 15.921875 -1.421875 10.953125 3.296875 \nQ 6 8.015625 6 15.921875 \nQ 6 25.140625 12.171875 29.828125 \nQ 18.359375 34.515625 30.609375 34.515625 \nL 43.21875 34.515625 \nL 43.21875 35.40625 \nQ 43.21875 41.609375 39.140625 45 \nQ 35.0625 48.390625 27.6875 48.390625 \nQ 23 48.390625 18.546875 47.265625 \nQ 14.109375 46.140625 10.015625 43.890625 \nL 10.015625 52.203125 \nQ 14.9375 54.109375 19.578125 55.046875 \nQ 24.21875 56 28.609375 56 \nQ 40.484375 56 46.34375 49.84375 \nQ 52.203125 43.703125 52.203125 31.203125 \nz\n\" id=\"DejaVuSans-97\"/>\n <path d=\"M 54.890625 33.015625 \nL 54.890625 0 \nL 45.90625 0 \nL 45.90625 32.71875 \nQ 45.90625 40.484375 42.875 44.328125 \nQ 39.84375 48.1875 33.796875 48.1875 \nQ 26.515625 48.1875 22.3125 43.546875 \nQ 18.109375 38.921875 18.109375 30.90625 \nL 18.109375 0 \nL 9.078125 0 \nL 9.078125 54.6875 \nL 18.109375 54.6875 \nL 18.109375 46.1875 \nQ 21.34375 51.125 25.703125 53.5625 \nQ 30.078125 56 35.796875 56 \nQ 45.21875 56 50.046875 50.171875 \nQ 54.890625 44.34375 54.890625 33.015625 \nz\n\" id=\"DejaVuSans-110\"/>\n </defs>\n <g transform=\"translate(36.366863 423.025903)rotate(-30)scale(0.12 -0.12)\">\n <use xlink:href=\"#DejaVuSans-74\"/>\n <use x=\"29.492188\" xlink:href=\"#DejaVuSans-97\"/>\n <use x=\"90.771484\" xlink:href=\"#DejaVuSans-110\"/>\n </g>\n <!-- 2012 -->\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA4kAAAHVCAYAAABc/b7wAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nOy9d5xfVZ3//zopEBGwIOiu7Bp0bYuIBXdtYMOKosh3VwHLuqv+lNXVdReNuCgdpBuahNBNQkASIKQnpPdJnfRkJtOSTO8zmfb5nN8fn8+duZ/7Obff+7n3fu7r6SMyc8u5Z255n/M+7yaklCCEEEIIIYQQQgBgXNQdIIQQQgghhBASH6gkEkIIIYQQQggZhUoiIYQQQgghhJBRqCQSQgghhBBCCBmFSiIhhBBCCCGEkFGoJBJCCCGEEEIIGWVC1B2Igje96U1y8uTJUXeDEEIIIYQQQiJh69atrVLKM1X7UqkkTp48GRUVFVF3gxBCCCGEEEIiQQhRa7aP7qaEEEIIIYQQQkahkkgIIYQQQgghZBQqiYQQQgghhBBCRkllTCIhhBBCCCGEAMDw8DAaGhowMDAQdVdCYdKkSTj77LMxceJEx+dQSSSEEEIIIYSkloaGBpx22mmYPHkyhBBRdydQpJRoa2tD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nAzWYnrX96Dho5+5f7VB1tC7wMhJL7YqgoKMRXnBa7m7gFMnjIf2+qCcecvd2L8KEkCUa09jMvP9LM6wXH/q4dL1COSZKgkktRSisF5W10Hnlxfg1/N3qnc/6O
},
"metadata": {
"needs_background": "light"
}
}
],
4 years ago
"source": [
"energy.plot(y='load', subplots=True, figsize=(15, 8), fontsize=12)\n",
"plt.xlabel('timestamp', fontsize=12)\n",
"plt.ylabel('load', fontsize=12)\n",
"plt.show()"
]
},
{
"source": [
4 years ago
"## Create training and testing data sets\n"
],
"cell_type": "markdown",
"metadata": {}
4 years ago
},
{
"cell_type": "code",
4 years ago
"execution_count": 5,
4 years ago
"metadata": {},
"outputs": [],
"source": [
"train_start_dt = '2014-11-01 00:00:00'\n",
"test_start_dt = '2014-12-30 00:00:00' "
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 6,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1080x576 with 1 Axes>",
4 years ago
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"523.819625pt\" version=\"1.1\" viewBox=\"0 0 904.55375 523.819625\" width=\"904.55375pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 523.819625 \nL 904.55375 523.819625 \nL 904.55375 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 60.35375 442.08 \nL 897.35375 442.08 \nL 897.35375 7.2 \nL 60.35375 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"m2e6b25e349\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"60.35375\" xlink:href=\"#m2e6b25e349\" y=\"442.08\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- -->\n <g transform=\"translate(60.35375 458.198125)scale(0.12 -0.12)\"/>\n <!-- -->\n <g transform=\"translate(60.35375 471.6355)scale(0.12 -0.12)\"/>\n <!-- Nov -->\n <defs>\n <path d=\"M 9.8125 72.90625 \nL 23.09375 72.90625 \nL 55.421875 11.921875 \nL 55.421875 72.90625 \nL 64.984375 72.90625 \nL 64.984375 0 \nL 51.703125 0 \nL 19.390625 60.984375 \nL 19.390625 0 \nL 9.8125 0 \nz\n\" id=\"DejaVuSans-78\"/>\n <path d=\"M 30.609375 48.390625 \nQ 23.390625 48.390625 19.1875 42.75 \nQ 14.984375 37.109375 14.984375 27.296875 \nQ 14.984375 17.484375 19.15625 11.84375 \nQ 23.34375 6.203125 30.609375 6.203125 \nQ 37.796875 6.203125 41.984375 11.859375 \nQ 46.1875 17.53125 46.1875 27.296875 \nQ 46.1875 37.015625 41.984375 42.703125 \nQ 37.796875 48.390625 30.609375 48.390625 \nz\nM 30.609375 56 \nQ 42.328125 56 49.015625 48.375 \nQ 55.71875 40.765625 55.71875 27.296875 \nQ 55.71875 13.875 49.015625 6.21875 \nQ 42.328125 -1.421875 30.609375 -1.421875 \nQ 18.84375 -1.421875 12.171875 6.21875 \nQ 5.515625 13.875 5.515625 27.296875 \nQ 5.515625 40.765625 12.171875 48.375 \nQ 18.84375 56 30.609375 56 \nz\n\" id=\"DejaVuSans-111\"/>\n <path d=\"M 2.984375 54.6875 \nL 12.5 54.6875 \nL 29.59375 8.796875 \nL 46.6875 54.6875 \nL 56.203125 54.6875 \nL 35.6875 0 \nL 23.484375 0 \nz\n\" id=\"DejaVuSans-118\"/>\n </defs>\n <g transform=\"translate(48.6425 485.072875)scale(0.12 -0.12)\">\n <use xlink:href=\"#DejaVuSans-78\"/>\n <use x=\"74.804688\" xlink:href=\"#DejaVuSans-111\"/>\n <use x=\"135.986328\" xlink:href=\"#DejaVuSans-118\"/>\n </g>\n <!-- 2014 -->\n <defs>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20.453125 19.1875 8.296875 \nz\n\" id=\"DejaVuSans-50\"/>\n <path d=\"M 31.78125 66.40625 \nQ 24.171875 66.40625 20.328125 58.90625 \nQ 16.5 51.421875 16.5 36.375 \nQ 16.5 21.390625 20.328125 13.890625 \nQ 24.171875 6.390625 31.78125 6.390625 \nQ 39.453125 6.390625 43.28125 13.890625 \nQ 47.125 21.390625 47.125 36.375 \nQ 47.125 51.421875 43.28125 58.90625 \nQ 39.453125 66.40625 31.7
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA4kAAAITCAYAAACqpFnEAAAABHNCSVQICAgIfAhkiAAAAA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AI2xKtNeKsKFEyiYIgCAUSJAqCIAiCsC3pZ1lEAFiOpU+iIGxHtNarv2iT4/MZJUgUBEEQBGFb0rfMaiSTKAjbj263i1OnTm3pQFFrjVOnTqHb7bLGibupIAiCIAjbktjKJIq7qSBsPy666CIcPnwYJ06c2Ohd4bF0FujPA1OPc3p5t9vFRRddxNqEBImCIAiCIGxL+qlkEgVhO9NqtXDJJZds9G7wectO8/P3pgGl1mUTIjcVBEEQBGFbInJTQRA2Ncuz6/bWEiQKgiAIgrAtEbmpIAibmvn1k8lKkCgIgiAIwrakJ5lEQRA2I91d5ufCqXXbhASJgiAIgiBsSyiTGAUKyxIkCoKwWRjLgsT5k+u2CQkSBUEQBEHYllBN4ng7lEyiIAibh7Hd5ueCBImCIAiCIAjnFAoSJzuRZBIFQdg8UJAomURBEARBEIRzS5wauel4J0IvTlhjj04vYn45Xo/dEgRBGEzYNj/7i+u2CQkSBUEQBEHYllBN4ng7ZLub/vu3/Rt+4QM3rcduCYIgDCbNFrXipXXbhASJgiAIgiBsS1JtgsRu5FeTeMfhmXO9S4IgCKujKUhcXrdNSJAoCIIgCMK2JMnkpp1WgFQDaapXGVEeJwiCsCGkmdRdMomCIAiCIAjnliTLJHaiEADQT92yieKEKgjChkL3KskkCoIgCIIgnFtSK5MIFDWKq7HU55ncCIIg1LHUT3DVLYe
},
"metadata": {
"needs_background": "light"
}
}
],
4 years ago
"source": [
"energy[(energy.index < test_start_dt) & (energy.index >= train_start_dt)][['load']].rename(columns={'load':'train'}) \\\n",
" .join(energy[test_start_dt:][['load']].rename(columns={'load':'test'}), how='outer') \\\n",
" .plot(y=['train', 'test'], figsize=(15, 8), fontsize=12)\n",
"plt.xlabel('timestamp', fontsize=12)\n",
"plt.ylabel('load', fontsize=12)\n",
"plt.show()"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 7,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Training data shape: (1416, 1)\nTest data shape: (48, 1)\n"
]
}
],
4 years ago
"source": [
"train = energy.copy()[(energy.index >= train_start_dt) & (energy.index < test_start_dt)][['load']]\n",
"test = energy.copy()[energy.index >= test_start_dt][['load']]\n",
"\n",
"print('Training data shape: ', train.shape)\n",
"print('Test data shape: ', test.shape)"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 8,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" load\n",
"2014-11-01 00:00:00 0.10\n",
"2014-11-01 01:00:00 0.07\n",
"2014-11-01 02:00:00 0.05\n",
"2014-11-01 03:00:00 0.04\n",
"2014-11-01 04:00:00 0.06\n",
"2014-11-01 05:00:00 0.10\n",
"2014-11-01 06:00:00 0.19\n",
"2014-11-01 07:00:00 0.31\n",
"2014-11-01 08:00:00 0.40\n",
"2014-11-01 09:00:00 0.48"
],
"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>load</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2014-11-01 00:00:00</th>\n <td>0.10</td>\n </tr>\n <tr>\n <th>2014-11-01 01:00:00</th>\n <td>0.07</td>\n </tr>\n <tr>\n <th>2014-11-01 02:00:00</th>\n <td>0.05</td>\n </tr>\n <tr>\n <th>2014-11-01 03:00:00</th>\n <td>0.04</td>\n </tr>\n <tr>\n <th>2014-11-01 04:00:00</th>\n <td>0.06</td>\n </tr>\n <tr>\n <th>2014-11-01 05:00:00</th>\n <td>0.10</td>\n </tr>\n <tr>\n <th>2014-11-01 06:00:00</th>\n <td>0.19</td>\n </tr>\n <tr>\n <th>2014-11-01 07:00:00</th>\n <td>0.31</td>\n </tr>\n <tr>\n <th>2014-11-01 08:00:00</th>\n <td>0.40</td>\n </tr>\n <tr>\n <th>2014-11-01 09:00:00</th>\n <td>0.48</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
4 years ago
"execution_count": 8
4 years ago
}
],
4 years ago
"source": [
"scaler = MinMaxScaler()\n",
"train['load'] = scaler.fit_transform(train)\n",
"train.head(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Original vs scaled data:"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 9,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
4 years ago
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"250.45375pt\" version=\"1.1\" viewBox=\"0 0 385.148125 250.45375\" width=\"385.148125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 250.45375 \nL 385.148125 250.45375 \nL 385.148125 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.148125 224.64 \nL 377.948125 224.64 \nL 377.948125 7.2 \nL 43.148125 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"patch_3\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 58.366307 224.64 \nL 61.409943 224.64 \nL 61.409943 214.538258 \nL 58.366307 214.538258 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_4\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 61.409943 224.64 \nL 64.45358 224.64 \nL 64.45358 194.334774 \nL 61.409943 194.334774 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_5\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 64.45358 224.64 \nL 67.497216 224.64 \nL 67.497216 224.64 \nL 64.45358 224.64 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_6\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 67.497216 224.64 \nL 70.540852 224.64 \nL 70.540852 189.283902 \nL 67.497216 189.283902 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_7\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 70.540852 224.64 \nL 73.584489 224.64 \nL 73.584489 184.233031 \nL 70.540852 184.233031 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_8\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 73.584489 224.64 \nL 76.628125 224.64 \nL 76.628125 179.18216 \nL 73.584489 179.18216 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_9\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 76.628125 224.64 \nL 79.671761 224.64 \nL 79.671761 164.029547 \nL 76.628125 164.029547 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_10\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 79.671761 224.64 \nL 82.715398 224.64 \nL 82.715398 169.080418 \nL 79.671761 169.080418 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_11\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 82.715398 224.64 \nL 85.759034 224.64 \nL 85.759034 164.029547 \nL 82.715398 164.029547 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_12\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 85.759034 224.64 \nL 88.80267 224.64 \nL 88.80267 164.029547 \nL 85.759034 164.029547 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_13\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 88.80267 224.64 \nL 91.846307 224.64 \nL 91.846307 153.927805 \nL 88.80267 153.927805 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_14\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 91.846307 224.64 \nL 94.889943 224.64 \nL 94.889943 184.233031 \nL 91.846307 184.233031 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_15\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 94.889943 224.64 \nL 97.93358 224.64 \nL 97.93358 108.469965 \nL 94.889943 108.469965 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_16\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 97.93358 224.64 \nL 100.977216 224.64 \nL 100.977216 138.775192 \nL 97.93358 138.775192 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_17\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 100.977216 224.64 \nL 104.020852 224.64 \nL 104.020852 148.876934 \nL 100.977216 148.876934 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_18\">\n <path clip-path=\"url(#p9cfa12f1f5)\" d=\"M 104.020852 224.64 \nL 107.064489 224.64 \nL 107.064489 148.876934 \nL 104.020852
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAAD7CAYAAACMlyg3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAZ+klEQVR4nO3df5BV5Z3n8fdHoOjwKyq0ZFYGOroRGBED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AzKzAnATMzArMScDMrMAyJQFJp+QdiJmZ1V7WjuHbJQ0F7gaWR0T5oyHNLAfuhLW8ZWoJRMQs4AvAHwNrJa2Q9Ke5RmZmZrnL3CcQERuBbwF/TfKcgNsktUu6qKvtJQ2VdKekTZJ2SnpO0p+lZS2SQlJHybKoL07IzMyyy3Q5SNJU4ArgPOBR4PyIeFbSvwP+BVhZ4dhvkCSM14FzgZ+V9S8cHREHexG/mZn1QtY+gf8F/BC4NiL2dK6MiDclfaurHSJiF7C4ZNXDkl4FZgBrjyxcMzPrS1mTwHnAnoh4F0DSUUBTROyOiHuyHEDSWOAkYEPJ6k2SgqR18VcRsTV76GZm1ltZk8Bq4GygI309DPgn4FNZdpY0BFgOLIuIdkkjgJnAc8Bo4Htp+Tld7LsQWAgwfvz4jOEWi0eQFFvp778321d7HBsYsnYMN0VEZwIg/XlYlh3TVsM9wH7g6s79I6ItIg5GxDvp+s9JGlm+f0QsjYjWiGhtbm7OGK6ZmWWRNQnskjS984WkGcCebrbv3E7AncBYYF5EHKiwaVQZj5mZ9YGsl4O
},
"metadata": {
"needs_background": "light"
}
},
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
4 years ago
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"250.45375pt\" version=\"1.1\" viewBox=\"0 0 385.148125 250.45375\" width=\"385.148125pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 250.45375 \nL 385.148125 250.45375 \nL 385.148125 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 43.148125 224.64 \nL 377.948125 224.64 \nL 377.948125 7.2 \nL 43.148125 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"patch_3\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 58.366307 224.64 \nL 61.409943 224.64 \nL 61.409943 214.538258 \nL 58.366307 214.538258 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_4\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 61.409943 224.64 \nL 64.45358 224.64 \nL 64.45358 194.334774 \nL 61.409943 194.334774 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_5\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 64.45358 224.64 \nL 67.497216 224.64 \nL 67.497216 224.64 \nL 64.45358 224.64 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_6\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 67.497216 224.64 \nL 70.540852 224.64 \nL 70.540852 189.283902 \nL 67.497216 189.283902 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_7\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 70.540852 224.64 \nL 73.584489 224.64 \nL 73.584489 184.233031 \nL 70.540852 184.233031 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_8\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 73.584489 224.64 \nL 76.628125 224.64 \nL 76.628125 179.18216 \nL 73.584489 179.18216 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_9\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 76.628125 224.64 \nL 79.671761 224.64 \nL 79.671761 164.029547 \nL 76.628125 164.029547 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_10\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 79.671761 224.64 \nL 82.715398 224.64 \nL 82.715398 169.080418 \nL 79.671761 169.080418 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_11\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 82.715398 224.64 \nL 85.759034 224.64 \nL 85.759034 164.029547 \nL 82.715398 164.029547 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_12\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 85.759034 224.64 \nL 88.80267 224.64 \nL 88.80267 164.029547 \nL 85.759034 164.029547 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_13\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 88.80267 224.64 \nL 91.846307 224.64 \nL 91.846307 153.927805 \nL 88.80267 153.927805 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_14\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 91.846307 224.64 \nL 94.889943 224.64 \nL 94.889943 184.233031 \nL 91.846307 184.233031 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_15\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 94.889943 224.64 \nL 97.93358 224.64 \nL 97.93358 108.469965 \nL 94.889943 108.469965 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_16\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 97.93358 224.64 \nL 100.977216 224.64 \nL 100.977216 138.775192 \nL 97.93358 138.775192 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_17\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 100.977216 224.64 \nL 104.020852 224.64 \nL 104.020852 148.876934 \nL 100.977216 148.876934 \nz\n\" style=\"fill:#1f77b4;\"/>\n </g>\n <g id=\"patch_18\">\n <path clip-path=\"url(#pe1158567c2)\" d=\"M 104.020852 224.64 \nL 107.064489 224.64 \nL 107.064489 148.876934 \nL 104.020852
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYEAAAD7CAYAAACMlyg3AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAaCklEQVR4nO3de5RV5Znn8e+PSyjlIhEK1GBZagJeQBQL7ehSM9EWO2omhjjRqOOltaIOsTNZzdLJ0oTYtunOmpl0JEokbTAg2iRpcKKxXYKXVmNPQsE0ERQ0LsHQogIJSCF3n/ljn9JjUUXtU5x9Tp3av89aZ8m+nf285+B5ePfz7ncrIjAzs3zqU+0AzMysepwEzMxyzEnAzCzHnATMzHLMScDMLMf6VTuAUgwfPjwaGxurHYaZWU1ZsmTJhoio72hbTSWBxsZGWlpaqh2GmVlNkbSms22+HGRmlmNOAmZmOeYkYGaWYzVVEzCz2rJr1y7Wrl3L9u3bqx1KLtTV1TFq1Cj69++f+hgnATPLzNq1axk8eDCNjY1IqnY4vVpEsHHjRtauXcuRRx6Z+jhfDjKzzGzfvp1hw4Y5AVSAJIYNG1Zyr8tJwMwy5QRQOd35rJ0EzMxyzDUBM6uYxlt+Vdb3W/1355f1/To8x+rVXHDBBSxfvjz1MVdddRUXXHABX/rSl1Ktr0RMnXESMMuB4h/fSvxwWu3w5SAz67W2bt3K+eefz/jx4xk7dizz5s0DYPHixZx22mmMHz+eU045hS1btrB69WrOOOMMJkyYwIQJE3jhhRf2er89e/YwdepUJk6cyAknnMC9994LJCNzpkyZwpgxYzjnnHN45513uoztySef5KSTTmLcuHFcc8017NixA4Dbb7+diRMnMnbsWJqbm2l7+uOSJUsYP34848eP5+677y7XR1SZJCDpU5K2S3qgaN1XJK2RtFXSw5IOrkQsZpYfjz/+OIcddhjLli1j+fLlnHfeeezcuZMvf/nL/OAHP2DZsmUsWrSIAw44gBEjRrBw4UKWLl3KvHnzuOmmm/Z6v/vuu4+DDjqIxYsXs3jxYn784x/z+uuvs2DBAlatWsVLL73E7NmzO0wgxbZv385VV13FvHnzePHFF9m9ezczZswAYMqUKSxevJjly5ezbds2Hn30UQCuvvpqpk+fzrJly8r6GVWqJ3A3sLhtQdLxwL3AFcBI4D3gngrFYmY5MW7cOBYuXMjNN9/Mc889x0EHHcSqVas49NBDmThxIgBDhgyhX79+7Nq1i+uuu45x48Zx8cUX89JLL+31fk888QSzZ8/mxBNP5NRTT2Xjxo28+uqrPPvss1x66aX07duXww47jM9+9rP7jGvVqlUceeSRjB49GoArr7ySZ599FoCnn36aU089lXHjxvHUU0+xYsUKNm3axKZNmzjzzDMBuOKKK8r2GWVeE5B0CbAJeAH4ZGH1ZcAjEfFsYZ/bgJclDY6ILVnHZGb5MHr0aJYuXcpjjz3Grbfeytlnn81FF13U4b7f//73GTlyJMuWLeP999+nrq5ur30igunTpzNp0qSPrH/sscfKEu/27du58cYbaWlp4fDDD2fatGmZ322daU9A0hDgduAb7TYdD3zQp4mI14CdwOgO3qNZUouklvXr12cZrlnuNN7yqw9evdGbb77JgQceyOWXX87UqVNZunQpY8aMYd26dSxenFyc2LJlC7t372bz5s0ceuih9OnThzlz5rBnz5693m/SpEnMmDGDXbt2AfDKK6+wdetWzjzzTObNm8eePXtYt24dTz/99D7jGjNmDKtXr+b3v/89AHPmzOGss8764Ad/+PDhtLa28otf/AKAoUOHMnToUJ5//nkA5s6dW54PiOx7An8D3BcRa9vdxDAI2Nxu383A4PZvEBEzgZkATU1NkVGcZlYBlR6Z9OKLLzJ16lT69OlD//79mTFjBh/72MeYN28eX/va19i2bRsHHHAAixYt4sYbb2Ty5MnMnj2b8847j4EDB+71ftdeey2rV69mwoQJRAT19fU8/PDDXHTRRTz11FMcd9xxNDQ08OlPf3qfcdXV1TFr1iwuvvhidu/ezcSJE7n++usZMGAA1113HWPHjuWQQw754JIVwKxZs7jmmmuQx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4P3CHpZEnDgfnAbcDBQAswL+NYzMysnUxvFouIFcWLhdfRwMnAioj4OYCkacAGScdExMosYzIzsw9lXhOQdI+k94CVwDrgMeB4YFnbPhGxFXitsL798c2SWiS1rF+/PutwzcxyJfMkEBE3AoOBM0guAe0ABgGb2+26ubBf++NnRkRTRDTV19dnHa6ZWa5UZHRQROyJiOeBUcANQCswpN1uQ4AtlYjHzMwSlR4i2o+kJrACGN+2UtLAovVmZlYhmSUBSSMkXSJpkKS+kiYBlwJPAguAsZImS6oDvgX8zkVhM7PKynJ0UJBc+vkRSbJZA3w9In4JIGky8EPgAeA3wCUZxmLWI2Q9rbSnrbZSZZYEImI9cNY+ti8Cjsnq/GZm1jVPG2FmlmNOAmZmOeYkYGaWY37GsFkP4+KuVZJ7AmZmOeYkYGaWY04CZmY55iRgZpZjLgybWUlcuO5d3BMwM8sxJwEzsxxzEjAzy7FUSUDSuKwDMTOzyktbGL5H0gDgfmBuRLR/NKSZZcBFWMtaqp5ARJwBXAYcDiyR9KCkP880MjMzy1zqmkBEvArcCtxM8pyAuyStlPTFjvaXNEDSfZLWSNoi6d8l/UVhW6OkkNRa9LqtHA0yM7P0Ul0OknQCcDVwPrAQuDAilko6DPg3YH4n7/0HkoTxBvA54Gft6gtDI2L3fsRvZmb7IW1NYDrwj8A3I2Jb28qIeFPSrR0dEBFbgWlFqx6V9DpwMrCke+GamVk5pU0C5wPbImIPgKQ+QF1EvBcRc9K8gaSRwGhgRdHqNZKCpHcxNSI2pA/dzMz2V9oksAg4B2gtLB8IPAGcluZgSf2BucBPI2KlpEHARODfgWHA3YXtkzo
},
"metadata": {
"needs_background": "light"
}
}
],
4 years ago
"source": [
"energy[(energy.index >= train_start_dt) & (energy.index < test_start_dt)][['load']].rename(columns={'load':'original load'}).plot.hist(bins=100, fontsize=12)\n",
"train.rename(columns={'load':'scaled load'}).plot.hist(bins=100, fontsize=12)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's also scale the test data"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 10,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" load\n",
"2014-12-30 00:00:00 0.33\n",
"2014-12-30 01:00:00 0.29\n",
"2014-12-30 02:00:00 0.27\n",
"2014-12-30 03:00:00 0.27\n",
"2014-12-30 04:00:00 0.30"
],
"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>load</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2014-12-30 00:00:00</th>\n <td>0.33</td>\n </tr>\n <tr>\n <th>2014-12-30 01:00:00</th>\n <td>0.29</td>\n </tr>\n <tr>\n <th>2014-12-30 02:00:00</th>\n <td>0.27</td>\n </tr>\n <tr>\n <th>2014-12-30 03:00:00</th>\n <td>0.27</td>\n </tr>\n <tr>\n <th>2014-12-30 04:00:00</th>\n <td>0.30</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
4 years ago
"execution_count": 10
4 years ago
}
],
4 years ago
"source": [
"test['load'] = scaler.transform(test)\n",
"test.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Implement ARIMA method"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 11,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Forecasting horizon: 3 hours\n"
]
}
],
4 years ago
"source": [
"# Specify the number of steps to forecast ahead\n",
"HORIZON = 3\n",
"print('Forecasting horizon:', HORIZON, 'hours')"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 29,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
4 years ago
" SARIMAX Results \n==========================================================================================\nDep. Variable: load No. Observations: 1416\nModel: SARIMAX(4, 1, 0)x(1, 1, 0, 24) Log Likelihood 3477.239\nDate: Fri, 14 May 2021 AIC -6942.477\nTime: 17:05:41 BIC -6911.050\nSample: 11-01-2014 HQIC -6930.725\n - 12-29-2014 \nCovariance Type: opg \n==============================================================================\n coef std err z P>|z| [0.025 0.975]\n------------------------------------------------------------------------------\nar.L1 0.8403 0.016 52.226 0.000 0.809 0.872\nar.L2 -0.5220 0.034 -15.388 0.000 -0.588 -0.456\nar.L3 0.1536 0.044 3.470 0.001 0.067 0.240\nar.L4 -0.0778 0.036 -2.158 0.031 -0.148 -0.007\nar.S.L24 -0.2327 0.024 -9.718 0.000 -0.280 -0.186\nsigma2 0.0004 8.32e-06 47.358 0.000 0.000 0.000\n===================================================================================\nLjung-Box (L1) (Q): 0.05 Jarque-Bera (JB): 1464.60\nProb(Q): 0.83 Prob(JB): 0.00\nHeteroskedasticity (H): 0.84 Skew: 0.14\nProb(H) (two-sided): 0.07 Kurtosis: 8.02\n===================================================================================\n\nWarnings:\n[1] Covariance matrix calculated using the outer product of gradients (complex-step).\n"
4 years ago
]
}
],
4 years ago
"source": [
"order = (4, 1, 0)\n",
"seasonal_order = (1, 1, 0, 24)\n",
"\n",
"model = SARIMAX(endog=train, order=order, seasonal_order=seasonal_order)\n",
"results = model.fit()\n",
"\n",
4 years ago
"print(results.summary())\n"
4 years ago
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we display the distribution of residuals. A zero mean in the residuals may indicate that there is no bias in the prediction. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Evaluate the model"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a test data point for each HORIZON step."
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 13,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" load load+1 load+2\n",
"2014-12-30 00:00:00 0.33 0.29 0.27\n",
"2014-12-30 01:00:00 0.29 0.27 0.27\n",
"2014-12-30 02:00:00 0.27 0.27 0.30\n",
"2014-12-30 03:00:00 0.27 0.30 0.41\n",
"2014-12-30 04:00:00 0.30 0.41 0.57"
],
"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>load</th>\n <th>load+1</th>\n <th>load+2</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2014-12-30 00:00:00</th>\n <td>0.33</td>\n <td>0.29</td>\n <td>0.27</td>\n </tr>\n <tr>\n <th>2014-12-30 01:00:00</th>\n <td>0.29</td>\n <td>0.27</td>\n <td>0.27</td>\n </tr>\n <tr>\n <th>2014-12-30 02:00:00</th>\n <td>0.27</td>\n <td>0.27</td>\n <td>0.30</td>\n </tr>\n <tr>\n <th>2014-12-30 03:00:00</th>\n <td>0.27</td>\n <td>0.30</td>\n <td>0.41</td>\n </tr>\n <tr>\n <th>2014-12-30 04:00:00</th>\n <td>0.30</td>\n <td>0.41</td>\n <td>0.57</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
4 years ago
"execution_count": 13
4 years ago
}
],
4 years ago
"source": [
"test_shifted = test.copy()\n",
"\n",
"for t in range(1, HORIZON):\n",
" test_shifted['load+'+str(t)] = test_shifted['load'].shift(-t, freq='H')\n",
" \n",
"test_shifted = test_shifted.dropna(how='any')\n",
"test_shifted.head(5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make predictions on the test data"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 14,
4 years ago
"metadata": {
"scrolled": true
},
4 years ago
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"2014-12-30 00:00:00\n",
"1 : predicted = [0.32 0.29 0.28] expected = [0.32945389435989236, 0.2900626678603402, 0.2739480752014323]\n",
"2014-12-30 01:00:00\n",
"2 : predicted = [0.3 0.29 0.3 ] expected = [0.2900626678603402, 0.2739480752014323, 0.26812891674127126]\n",
"2014-12-30 02:00:00\n",
"3 : predicted = [0.27 0.28 0.32] expected = [0.2739480752014323, 0.26812891674127126, 0.3025962399283795]\n",
"2014-12-30 03:00:00\n",
"4 : predicted = [0.28 0.32 0.42] expected = [0.26812891674127126, 0.3025962399283795, 0.40823634735899716]\n",
"2014-12-30 04:00:00\n",
"5 : predicted = [0.3 0.39 0.54] expected = [0.3025962399283795, 0.40823634735899716, 0.5689346463742166]\n",
"2014-12-30 05:00:00\n",
"6 : predicted = [0.4 0.55 0.66] expected = [0.40823634735899716, 0.5689346463742166, 0.6799462846911368]\n",
"2014-12-30 06:00:00\n",
"7 : predicted = [0.57 0.68 0.75] expected = [0.5689346463742166, 0.6799462846911368, 0.7309758281110115]\n",
"2014-12-30 07:00:00\n",
"8 : predicted = [0.68 0.75 0.8 ] expected = [0.6799462846911368, 0.7309758281110115, 0.7511190689346463]\n",
"2014-12-30 08:00:00\n",
"9 : predicted = [0.75 0.8 0.82] expected = [0.7309758281110115, 0.7511190689346463, 0.7636526410026856]\n",
"2014-12-30 09:00:00\n",
"10 : predicted = [0.77 0.78 0.78] expected = [0.7511190689346463, 0.7636526410026856, 0.7381378692927483]\n",
"2014-12-30 10:00:00\n",
"11 : predicted = [0.76 0.75 0.74] expected = [0.7636526410026856, 0.7381378692927483, 0.7188898836168307]\n",
"2014-12-30 11:00:00\n",
"12 : predicted = [0.77 0.76 0.75] expected = [0.7381378692927483, 0.7188898836168307, 0.7090420769919425]\n",
"2014-12-30 12:00:00\n",
"13 : predicted = [0.7 0.68 0.69] expected = [0.7188898836168307, 0.7090420769919425, 0.7081468218442255]\n",
"2014-12-30 13:00:00\n",
"14 : predicted = [0.72 0.73 0.76] expected = [0.7090420769919425, 0.7081468218442255, 0.7385854968666068]\n",
"2014-12-30 14:00:00\n",
"15 : predicted = [0.71 0.73 0.86] expected = [0.7081468218442255, 0.7385854968666068, 0.8478066248880931]\n",
"2014-12-30 15:00:00\n",
"16 : predicted = [0.73 0.85 0.97] expected = [0.7385854968666068, 0.8478066248880931, 0.9516562220232765]\n",
"2014-12-30 16:00:00\n",
"17 : predicted = [0.87 0.99 0.97] expected = [0.8478066248880931, 0.9516562220232765, 0.934198746642793]\n",
"2014-12-30 17:00:00\n",
"18 : predicted = [0.94 0.92 0.86] expected = [0.9516562220232765, 0.934198746642793, 0.8876454789615038]\n",
"2014-12-30 18:00:00\n",
"19 : predicted = [0.94 0.89 0.82] expected = [0.934198746642793, 0.8876454789615038, 0.8294538943598924]\n",
"2014-12-30 19:00:00\n",
"20 : predicted = [0.88 0.82 0.71] expected = [0.8876454789615038, 0.8294538943598924, 0.7197851387645477]\n",
"2014-12-30 20:00:00\n",
"21 : predicted = [0.83 0.72 0.58] expected = [0.8294538943598924, 0.7197851387645477, 0.5747538048343777]\n",
"2014-12-30 21:00:00\n",
"22 : predicted = [0.72 0.58 0.47] expected = [0.7197851387645477, 0.5747538048343777, 0.4592658907788718]\n",
"2014-12-30 22:00:00\n",
"23 : predicted = [0.58 0.47 0.39] expected = [0.5747538048343777, 0.4592658907788718, 0.3858549686660697]\n",
"2014-12-30 23:00:00\n",
"24 : predicted = [0.46 0.38 0.34] expected = [0.4592658907788718, 0.3858549686660697, 0.34377797672336596]\n",
"2014-12-31 00:00:00\n",
"25 : predicted = [0.38 0.34 0.33] expected = [0.3858549686660697, 0.34377797672336596, 0.32542524619516544]\n",
"2014-12-31 01:00:00\n",
"26 : predicted = [0.36 0.34 0.34] expected = [0.34377797672336596, 0.32542524619516544, 0.33034914950760963]\n",
"2014-12-31 02:00:00\n",
"27 : predicted = [0.32 0.32 0.35] expected = [0.32542524619516544, 0.33034914950760963, 0.3706356311548791]\n",
"2014-12-31 03:00:00\n",
"28 : predicted = [0.32 0.36 0.47] expected = [0.33034914950760963, 0.3706356311548791, 0.470008952551477]\n",
"2014-12-31 04:00:00\n",
"29 : predicted = [0.37 0.48 0.65] expected = [0.3706356311548791, 0.470008952551477, 0.6145926589077886]\n",
"2014-12-31 05:00:00\n",
"30 : predicted = [0.48 0.64 0.75] expected = [0.470008952551477, 0.6145926589077886, 0.7247090420769919]\n",
"2014-12-31 06:00:00\n",
"31 : predicted = [0.63 0.73 0.79] expected = [0.6145926589077886, 0.7247090420769919, 0.786034019695613]\n",
"2014-12-31 07:00:00\n",
"32 : predicted = [0.71 0.76 0.79] expected = [0.7247090420769919, 0.786034019695613, 0.8012533572068039]\n",
"2014-12-31 08:00:00\n",
"33 : predicted = [0.79 0.82 0.83] expected = [0.786034019695613, 0.8012533572068039, 0.7994628469113696]\n",
"2014-12-31 09:00:00\n",
"34 : predicted = [0.82 0.83 0.81] expected = [0.8012533572068039, 0.7994628469113696, 0.780214861235452]\n",
"2014-12-31 10:00:00\n",
"35 : predicted = [0.8 0.78 0.76] expected = [0.7994628469113696, 0.780214861235452, 0.7587287376902416]\n",
"2014-12-31 11:00:00\n",
"36 : predicted = [0.77 0.75 0.74] expected = [0.780214861235452, 0.7587287376902416, 0.7367949865711727]\n",
"2014-12-31 12:00:00\n",
"37 : predicted = [0.77 0.76 0.76] expected = [0.7587287376902416, 0.7367949865711727, 0.7188898836168307]\n",
"2014-12-31 13:00:00\n",
"38 : predicted = [0.75 0.75 0.78] expected = [0.7367949865711727, 0.7188898836168307, 0.7273948075201431]\n",
"2014-12-31 14:00:00\n",
"39 : predicted = [0.73 0.75 0.87] expected = [0.7188898836168307, 0.7273948075201431, 0.8299015219337511]\n",
"2014-12-31 15:00:00\n",
"40 : predicted = [0.74 0.85 0.96] expected = [0.7273948075201431, 0.8299015219337511, 0.909579230080573]\n",
"2014-12-31 16:00:00\n",
"41 : predicted = [0.83 0.94 0.93] expected = [0.8299015219337511, 0.909579230080573, 0.855863921217547]\n",
"2014-12-31 17:00:00\n",
"42 : predicted = [0.94 0.93 0.88] expected = [0.909579230080573, 0.855863921217547, 0.7721575649059982]\n",
"2014-12-31 18:00:00\n",
"43 : predicted = [0.87 0.82 0.77] expected = [0.855863921217547, 0.7721575649059982, 0.7023276633840643]\n",
"2014-12-31 19:00:00\n",
"44 : predicted = [0.79 0.73 0.63] expected = [0.7721575649059982, 0.7023276633840643, 0.6195165622202325]\n",
"2014-12-31 20:00:00\n",
"45 : predicted = [0.7 0.59 0.46] expected = [0.7023276633840643, 0.6195165622202325, 0.5425246195165621]\n",
"2014-12-31 21:00:00\n",
"46 : predicted = [0.6 0.47 0.36] expected = [0.6195165622202325, 0.5425246195165621, 0.4735899731423454]\n",
4 years ago
"CPU times: user 13min 24s, sys: 2min 53s, total: 16min 17s\n",
"Wall time: 2min 53s\n"
4 years ago
]
}
],
4 years ago
"source": [
"%%time\n",
"training_window = 720 # dedicate 30 days (720 hours) for training\n",
"\n",
"train_ts = train['load']\n",
"test_ts = test_shifted\n",
"\n",
"history = [x for x in train_ts]\n",
"history = history[(-training_window):]\n",
"\n",
"predictions = list()\n",
"\n",
"# let's user simpler model for demonstration\n",
"order = (2, 1, 0)\n",
"seasonal_order = (1, 1, 0, 24)\n",
"\n",
"for t in range(test_ts.shape[0]):\n",
" model = SARIMAX(endog=history, order=order, seasonal_order=seasonal_order)\n",
" model_fit = model.fit()\n",
" yhat = model_fit.forecast(steps = HORIZON)\n",
" predictions.append(yhat)\n",
" obs = list(test_ts.iloc[t])\n",
" # move the training window\n",
" history.append(obs[0])\n",
" history.pop(0)\n",
" print(test_ts.index[t])\n",
" print(t+1, ': predicted =', yhat, 'expected =', obs)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compare predictions to actual load"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 15,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" timestamp h prediction actual\n",
"0 2014-12-30 00:00:00 t+1 3,008.74 3,023.00\n",
"1 2014-12-30 01:00:00 t+1 2,955.53 2,935.00\n",
"2 2014-12-30 02:00:00 t+1 2,900.17 2,899.00\n",
"3 2014-12-30 03:00:00 t+1 2,917.69 2,886.00\n",
"4 2014-12-30 04:00:00 t+1 2,946.99 2,963.00"
],
"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>timestamp</th>\n <th>h</th>\n <th>prediction</th>\n <th>actual</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>2014-12-30 00:00:00</td>\n <td>t+1</td>\n <td>3,008.74</td>\n <td>3,023.00</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2014-12-30 01:00:00</td>\n <td>t+1</td>\n <td>2,955.53</td>\n <td>2,935.00</td>\n </tr>\n <tr>\n <th>2</th>\n <td>2014-12-30 02:00:00</td>\n <td>t+1</td>\n <td>2,900.17</td>\n <td>2,899.00</td>\n </tr>\n <tr>\n <th>3</th>\n <td>2014-12-30 03:00:00</td>\n <td>t+1</td>\n <td>2,917.69</td>\n <td>2,886.00</td>\n </tr>\n <tr>\n <th>4</th>\n <td>2014-12-30 04:00:00</td>\n <td>t+1</td>\n <td>2,946.99</td>\n <td>2,963.00</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
4 years ago
"execution_count": 15
4 years ago
}
],
4 years ago
"source": [
"eval_df = pd.DataFrame(predictions, columns=['t+'+str(t) for t in range(1, HORIZON+1)])\n",
"eval_df['timestamp'] = test.index[0:len(test.index)-HORIZON+1]\n",
"eval_df = pd.melt(eval_df, id_vars='timestamp', value_name='prediction', var_name='h')\n",
"eval_df['actual'] = np.array(np.transpose(test_ts)).ravel()\n",
"eval_df[['prediction', 'actual']] = scaler.inverse_transform(eval_df[['prediction', 'actual']])\n",
"eval_df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Compute the **mean absolute percentage error (MAPE)** over all predictions\n",
"\n",
"$$MAPE = \\frac{1}{n} \\sum_{t=1}^{n}|\\frac{actual_t - predicted_t}{actual_t}|$$"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 16,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"h\nt+1 0.01\nt+2 0.01\nt+3 0.02\nName: APE, dtype: float64\n"
]
}
],
4 years ago
"source": [
"if(HORIZON > 1):\n",
" eval_df['APE'] = (eval_df['prediction'] - eval_df['actual']).abs() / eval_df['actual']\n",
" print(eval_df.groupby('h')['APE'].mean())"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 17,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"One step forecast MAPE: 0.5570581332313952 %\n"
]
}
],
4 years ago
"source": [
"print('One step forecast MAPE: ', (mape(eval_df[eval_df['h'] == 't+1']['prediction'], eval_df[eval_df['h'] == 't+1']['actual']))*100, '%')"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 18,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Multi-step forecast MAPE: 1.1460048657704118 %\n"
]
}
],
4 years ago
"source": [
"print('Multi-step forecast MAPE: ', mape(eval_df['prediction'], eval_df['actual'])*100, '%')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the predictions vs the actuals for the first week of the test set"
]
},
{
"cell_type": "code",
4 years ago
"execution_count": 19,
4 years ago
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stderr",
"text": [
"No handles with labels found to put in legend.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 1080x576 with 1 Axes>",
4 years ago
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Created with matplotlib (https://matplotlib.org/) -->\n<svg height=\"481.571875pt\" version=\"1.1\" viewBox=\"0 0 899.46375 481.571875\" width=\"899.46375pt\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <defs>\n <style type=\"text/css\">\n*{stroke-linecap:butt;stroke-linejoin:round;white-space:pre;}\n </style>\n </defs>\n <g id=\"figure_1\">\n <g id=\"patch_1\">\n <path d=\"M 0 481.571875 \nL 899.46375 481.571875 \nL 899.46375 0 \nL 0 0 \nz\n\" style=\"fill:none;\"/>\n </g>\n <g id=\"axes_1\">\n <g id=\"patch_2\">\n <path d=\"M 55.26375 442.08 \nL 892.26375 442.08 \nL 892.26375 7.2 \nL 55.26375 7.2 \nz\n\" style=\"fill:#ffffff;\"/>\n </g>\n <g id=\"matplotlib.axis_1\">\n <g id=\"xtick_1\">\n <g id=\"line2d_1\">\n <defs>\n <path d=\"M 0 0 \nL 0 3.5 \n\" id=\"ma7d61060a5\" style=\"stroke:#000000;stroke-width:0.8;\"/>\n </defs>\n <g>\n <use style=\"stroke:#000000;stroke-width:0.8;\" x=\"93.309205\" xlink:href=\"#ma7d61060a5\" y=\"442.08\"/>\n </g>\n </g>\n <g id=\"text_1\">\n <!-- 12-30 00 -->\n <defs>\n <path d=\"M 12.40625 8.296875 \nL 28.515625 8.296875 \nL 28.515625 63.921875 \nL 10.984375 60.40625 \nL 10.984375 69.390625 \nL 28.421875 72.90625 \nL 38.28125 72.90625 \nL 38.28125 8.296875 \nL 54.390625 8.296875 \nL 54.390625 0 \nL 12.40625 0 \nz\n\" id=\"DejaVuSans-49\"/>\n <path d=\"M 19.1875 8.296875 \nL 53.609375 8.296875 \nL 53.609375 0 \nL 7.328125 0 \nL 7.328125 8.296875 \nQ 12.9375 14.109375 22.625 23.890625 \nQ 32.328125 33.6875 34.8125 36.53125 \nQ 39.546875 41.84375 41.421875 45.53125 \nQ 43.3125 49.21875 43.3125 52.78125 \nQ 43.3125 58.59375 39.234375 62.25 \nQ 35.15625 65.921875 28.609375 65.921875 \nQ 23.96875 65.921875 18.8125 64.3125 \nQ 13.671875 62.703125 7.8125 59.421875 \nL 7.8125 69.390625 \nQ 13.765625 71.78125 18.9375 73 \nQ 24.125 74.21875 28.421875 74.21875 \nQ 39.75 74.21875 46.484375 68.546875 \nQ 53.21875 62.890625 53.21875 53.421875 \nQ 53.21875 48.921875 51.53125 44.890625 \nQ 49.859375 40.875 45.40625 35.40625 \nQ 44.1875 33.984375 37.640625 27.21875 \nQ 31.109375 20.453125 19.1875 8.296875 \nz\n\" id=\"DejaVuSans-50\"/>\n <path d=\"M 4.890625 31.390625 \nL 31.203125 31.390625 \nL 31.203125 23.390625 \nL 4.890625 23.390625 \nz\n\" id=\"DejaVuSans-45\"/>\n <path d=\"M 40.578125 39.3125 \nQ 47.65625 37.796875 51.625 33 \nQ 55.609375 28.21875 55.609375 21.1875 \nQ 55.609375 10.40625 48.1875 4.484375 \nQ 40.765625 -1.421875 27.09375 -1.421875 \nQ 22.515625 -1.421875 17.65625 -0.515625 \nQ 12.796875 0.390625 7.625 2.203125 \nL 7.625 11.71875 \nQ 11.71875 9.328125 16.59375 8.109375 \nQ 21.484375 6.890625 26.8125 6.890625 \nQ 36.078125 6.890625 40.9375 10.546875 \nQ 45.796875 14.203125 45.796875 21.1875 \nQ 45.796875 27.640625 41.28125 31.265625 \nQ 36.765625 34.90625 28.71875 34.90625 \nL 20.21875 34.90625 \nL 20.21875 43.015625 \nL 29.109375 43.015625 \nQ 36.375 43.015625 40.234375 45.921875 \nQ 44.09375 48.828125 44.09375 54.296875 \nQ 44.09375 59.90625 40.109375 62.90625 \nQ 36.140625 65.921875 28.71875 65.921875 \nQ 24.65625 65.921875 20.015625 65.03125 \nQ 15.375 64.15625 9.8125 62.3125 \nL 9.8125 71.09375 \nQ 15.4375 72.65625 20.34375 73.4375 \nQ 25.25 74.21875 29.59375 74.21875 \nQ 40.828125 74.21875 47.359375 69.109375 \nQ 53.90625 64.015625 53.90625 55.328125 \nQ 53.90625 49.265625 50.4375 45.09375 \nQ 46.96875 40.921875 40.578125 39.3125 \nz\n\" id=\"DejaVuSans-51\"/>\n <path d=\"M 31.78125 66.40625 \nQ 24.171875 66.40625 20.328125 58.90625 \nQ 16.5 51.421875 16.5 36.375 \nQ 16.5 21.390625 20.328125 13.890625 \nQ 24.171875 6.390625 31.78125 6.390625 \nQ 39.453125 6.390625 43.28125 13.890625 \nQ 47.125 21.390625 47.125 36.375 \nQ 47.125 51.421875 43.28125 58.90625 \nQ 39.453125 66.40625 31.78125 66.40625 \nz\nM 31.78125 74.21875 \nQ 44.046875 74.21875
4 years ago
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA4QAAAHjCAYAAAB7INHwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAgAElEQVR4nOzdd3xV9f348de592bvhDBkhhEggCICIqCCgoJ7K462Wm1rtV+7tFpb/XVpq6211tFaR93WPVBQQXAwFBXUMMLeSHZyM26Se+/5/fG+J+ecDJYhN+P9fDx45JxzRz6xac59fz7vz/ttmKaJUkoppZRSSqnuxxPtASillFJKKaWUig4NCJVSSimllFKqm9KAUCmllFJKKaW6KQ0IlVJKKaWUUqqb0oBQKaWUUkoppbopDQiVUkoppZRSqpvyRXsAh1uPHj3MQYMGRXsYSimllFJKKRUVn3/+ebFpmtktPdblA8JBgwbx2WefRXsYSimllFJKKRUVhmFsa+0xTRlVSimllFJKqW5KA0KllFJKKaWU6qY0IFRKKaWUUkqpbqrL7yFUSimllFJKqa6ioaGBnTt3EggEmj0WHx9Pv379iImJOeD304BQKaWUUkoppTqJnTt3kpKSwqBBgzAMo/G6aZqUlJSwc+dOcnJyDvj9NGVUKaWUUkoppTqJQCBAVlaWKxgEMAyDrKysFlcO90UDQqWUUkoppZTqRJoG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xSSSppVGBYL9qxnb/9qJzjvsolN1daGoKsTlpFBJRSSnUdTauL3nef+/EdO2TVMD4
},
"metadata": {
"needs_background": "light"
}
}
],
4 years ago
"source": [
"if(HORIZON == 1):\n",
" ## Plotting single step forecast\n",
" eval_df.plot(x='timestamp', y=['actual', 'prediction'], style=['r', 'b'], figsize=(15, 8))\n",
"\n",
"else:\n",
" ## Plotting multi step forecast\n",
" plot_df = eval_df[(eval_df.h=='t+1')][['timestamp', 'actual']]\n",
" for t in range(1, HORIZON+1):\n",
" plot_df['t+'+str(t)] = eval_df[(eval_df.h=='t+'+str(t))]['prediction'].values\n",
"\n",
" fig = plt.figure(figsize=(15, 8))\n",
" ax = plt.plot(plot_df['timestamp'], plot_df['actual'], color='red', linewidth=4.0)\n",
" ax = fig.add_subplot(111)\n",
" for t in range(1, HORIZON+1):\n",
" x = plot_df['timestamp'][(t-1):]\n",
" y = plot_df['t+'+str(t)][0:len(x)]\n",
" ax.plot(x, y, color='blue', linewidth=4*math.pow(.9,t), alpha=math.pow(0.8,t))\n",
" \n",
" ax.legend(loc='best')\n",
" \n",
"plt.xlabel('timestamp', fontsize=12)\n",
"plt.ylabel('load', fontsize=12)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernel_info": {
"name": "python3"
},
"kernelspec": {
4 years ago
"name": "python37364bit8d3b438fb5fc4430a93ac2cb74d693a7",
"display_name": "Python 3.7.0 64-bit ('3.7')"
4 years ago
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
4 years ago
"version": "3.7.0"
4 years ago
},
"nteract": {
"version": "nteract-front-end@1.0.0"
4 years ago
},
"metadata": {
"interpreter": {
"hash": "70b38d7a306a849643e446cd70466270a13445e5987dfa1344ef2b127438fa4d"
}
4 years ago
}
},
"nbformat": 4,
"nbformat_minor": 2
}