pyFTSex/tutorial/darts/habr_CO2.ipynb

727 lines
1.5 MiB
Plaintext
Raw Normal View History

2024-08-15 12:15:32 +04:00
{
"cells": [
{
"cell_type": "markdown",
"id": "d90e18b1",
"metadata": {},
"source": [
"# Habr: Прогнозирование атмосферного CO2 с помощью Python\n",
"https://habr.com/en/articles/659405/\n",
"\n",
"Было выполнено много изменений данных и немного кода из-за сильных изменений pandas за 2 года (в основном пострадало считывание данных)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e9a5d759-ffb3-4d77-8170-edd8ca33d9bf",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"from statsmodels.tsa.seasonal import seasonal_decompose\n",
"from statsmodels.graphics.tsaplots import plot_acf, plot_pacf\n",
"from darts import TimeSeries\n",
"from darts.models import *\n",
"from darts.metrics import *\n",
"from darts.dataprocessing.transformers import Scaler\n",
"import logging\n",
"\n",
"mpl.rcParams['figure.dpi'] = 300\n",
"logging.disable(logging.CRITICAL)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6ee38c2a-b799-414f-b154-2d0ac1dcae7d",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"df = pd.read_csv('data/monthly_in_situ_co2_mlo.csv',\n",
" comment = '\"', header = [0], na_values = '-99.99')\n",
"\n",
"#cols = [' '.join(col).replace(' ', '') for col in df.columns.values]\n",
"#df.set_axis(cols, axis = 1) #, inplace = True\n",
"\n",
"# Converting Excel date format to datetime\n",
"# and setting as dataframe index\n",
"df['Datetime'] = pd.to_datetime(df['DateDays'], origin = '1899-12-30', unit = 'D')\n",
"\n",
"df.set_index('Datetime', inplace = True)\n",
"\n",
"df = df[['CO2']]\n",
"#df.rename(columns = {'CO2filled[ppm]': 'CO2'}, inplace = True)\n",
"df.dropna(inplace = True) \n",
"df = df.resample('ME').sum()"
]
},
{
"cell_type": "markdown",
"id": "a9f4d723-55d5-492f-89d4-808000b44f0f",
"metadata": {},
"source": [
"## Time Series Analysis"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5e531223-7bf1-48aa-be31-afc5288b1cff",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB98AAAV3CAYAAAD4ta+LAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/TGe4hAAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdd1xX5f//8ScbRWUoOBD33jtNy51ajrLUppmVlu29y/bO1qcyS7NhWtowTdPMXLn3REVRQRygosiG8/vDH3x9c84b3gsBfdxvN2+3zut9znVdwJsD8TzXdXkZhmEIAAAAAAAAAAAAAAC4zLukBwAAAAAAAAAAAAAAQFlH+A4AAAAAAAAAAAAAgJsI3wEAAAAAAAAAAAAAcBPhOwAAAAAAAAAAAAAAbiJ8BwAAAAAAAAAAAADATYTvAAAAAAAAAAAAAAC4ifAdAAAAAAAAAAAAAAA3Eb4DAAAAAAAAAAAAAOAmwncAAAAAAAAAAAAAANxE+A4AAAAAAAAAAAAAgJsI3wEAAAAAAAAAAAAAcBPhOwAAAAAAAAAAAAAAbiJ8BwAAAAAAAAAAAADATYTvAAAAAAAAAAAAAAC4ifAdAAAAAAAAAAAAAAA3Eb4DAAAAAAAAAAAAAOAmwncAAAAAAAAAAAAAANxE+A4AAAAAAAAAAAAAgJsI3wEAAAAAAAAAAAAAcBPhOwAAAAAAAAAAAAAAbiJ8BwAAAAAAAAAAAADATYTvAAAAAAAAAAAAAAC4ifAdAAAAAAAAAAAAAAA3Eb4DAAAAAAAAAAAAAOAmwncAAAAAAAAAAAAAANxE+A4AAAAAAAAAAAAAgJsI3wEAAAAAAAAAAAAAcBPhOwAAAAAAAAAAAAAAbiJ8BwAAAAAAAAAAAADATYTvAAAAQBn1zTffyMvLy+ZfbGzsBet//Pjxpv4BAMD/4Wdl6ZCenq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ERAWVbTEyMLr/8ct1xxx1uf28ZhqF//vlHPXr00MCBA50OembPnq3GjRvr888/z5/d5YodO3bouuuu0w033KDTp087ff0HH3ygOXPmKDMz0+UxpKam6pFHHtFVV12ls2fPutyOpyxcuFCNGzfWa6+9ppMnT7rVVlpamr777js1adJEDz74oE0YBADwvK1bt2r69On5x5UrV9aYMWNKcES40J544gmbbX4++OADJSUlleCIAADAxY5l5wEAAC4hU6ZM0euvv+7y9TNmzCgVYRhQ0hYuXFhoQB0QEKCuXbuqU6dOCg8PV3h4uAIDA3XmzBkdOHBA27Zt09KlS5WYmGi6du7cubrhhhsc3ibirbfe0rPPPivDMCxfb9u2rXr37q3IyEhVq1ZNqampOnz4sHbv3q05c+ZYBsqzZs3Stm3btHDhQo8shx8SEqKuXbuqQ4cOioiIUJUqVZSamqr9+/frn3/+0fLly03XLFq0SIMHD9aff/6pgIAAt8fgiqI+t6GhoerTp4+aNm2a/3U2DEOnTp3S/v37tW7dOq1cuVJpaWk212VlZemTTz7Ro48+yp7wAFCMnn/+eZt7+IMPPqigoKASHBEutPr16+uGG27QjBkzJJ17mPjtt9/WO++8U8IjAwAAFyvCdwAAgItYaGioTbD27bff6tVXX5W3t2sLIBVcuj4sLEwnTpxwa4xAWTN37lwNHTrUcnZ306ZN9fLLL+uaa64pcknb3NxcLVmyRJMmTdLPP/+s7Oxsp8fyxhtv6LnnnjPVvby8NGbMGD311FOqW7eu3euzsrI0b948Pf7449qzZ4/Na9HR0erevbuWL1+uGjVqOD224OBgjRgxQqNGjdJll11m977z8ssva9OmTbrrrru0fv16m9f++ecfvfnmmyWyPcPzzz9v92Gl/v3767nnnlOXLl1sZtNZSU1N1R9//KFPPvlEK1asKI6hAijFxo8fzxYzJWTHjh36448/8o99fX119913l+CIUFLuvffe/PBdkr744gs9//zzqlSpUgmOCgAAXKxYdh4AAOAidvXVVyskJCT/OC4uTn/99ZdLbe3cuVMrV67MP/bx8dGIESPcHSJQpmzatEkjRowwBe9+fn763//+p61bt2rYsGEO7SXr7e2tnj17atq0adq5c6cGDx7s1Fhmzpyp559/3lSPiorSihUr9MUXXxQavOeNe/DgwdqyZYsee+wx0+v79+/Xtdde69RS9jVq1NBHH32khIQETZw4UV26dCnygZ82bdrov//+U//+/U2vvf3224qLi3O4f0/46quvLIP36tWr659//tG8efPUrVu3IoN3SSpfvrxGjBih5cuXa9GiRWrRokVxDBkAUMCECRNsZr0PHjxY1atXL8ERoaR0795djRo1yj8+c+aMJk2aVIIjAgAAFzPCdwAAgItYYGCgbrrpJptawdnrjip4Xb9+/VyaDQuUVenp6brppptMWy9UqFBBc+fO1bhx4xwKY600aNBAv//+u6ZOnaoKFSoUef7hw4d11113mZZDr1mzphYvXqwuXbo41X9gYKDee+89vfDCC6bX1q5dqxdffNGhdp555hnFxMTowQcfVLly5Zwag7+/v3766SdTMJKenq6ff/7ZqbbcsXPnTj3wwAOmeuPGjfXff/+pZ8+eLrfdq1cvrV+/Xo8//rg7QwQAFCEpKUnff/+9Te3OO+8sodGgNBg9erTN8SeffKLc3NwSGg0AALiYEb4DAABc5Ar+oWn27NlKSkpyqo3s7Gx99913hbYLXOzeeOMN7dq1y1T/6aef1LdvX4/0MXLkSK1YsUI1a9Ys9LxHHnlEycnJNrXAwEAtWLBA9evXd7n/V155xfJ7+/3339f27duLvL5fv34KDAx0uf+KFStaBtNz5sxxuU1njR07Vunp6Ta1sLAw/fPPPx7Zn93f31/vvvuupk2bJn9/f7fbAwCYTZs2zeZeHhIS4rGf1Sibhg0bZnN84MABLV68uIRGAwAALmbs+Q4AAHCR69Chg1q1aqU
"text/plain": [
"<Figure size 2400x1500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"df.plot(figsize=(8,5))\n",
"plt.title('Monthly CO2 Concentration (ppm)')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "1d7cc8da-ed7c-4af1-81c0-e9732af7f0bc",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {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aebMmXJycrJx9/+vadOmpvG+ffvKYrGoZcuWevjwoSGfN2/eKPdyFAahAAAAAAAAAAAAAAAA8N568eKFGjdurNDQUKs1r1+/VqNGjRQYGBjtPhaLRWPHjtV3330ni8Vita5z585KlixZuFiiRInUrl07Q+3Tp081bdq0CPvOmDFDkydPNs1NnTpVH3/8sQ27N/rmm2/k5eVliC9btkx169bVTz/9ZMi5urpqxowZ0ernCAxCAQAAAAAAAAAAAAAA4L3Vt2/fsOvcInL9+nWtXr062n0GDx5sdSDpb1999ZV69uxpmuvUqZPixIljiI8bN06vXr0yfWb9+vVWr6erV6+e6tevH8murXNxcTG9sk+Sli9fbhrv06ePcufOHe2e9mIQCgAAAAAAAAAAAAAAAO+lixcvatKkSTbXRzbIZM327ds1d+5cq/msWbNq9uzZ2rNnjzw9PU1rUqRIoWbNmhnid+/e1Zw5cwzxX3/9VXXq1DE96Spt2rSaOnWq7V/Aiu+++06ZMmWyqTZ37tzq1auX3T3twSAUAAAAAAAAAAAAAAAA3ks9e/ZUcHCwIe7t7a1KlSoZ4vv27dPx48ej1OPVq1caOHCgac7T01NLly7V6dOn1bRpU7m5uUW4Vrdu3eTi4mKIjxo1Ktz3ePXqlWrWrKmXL18aauPEiaPly5crceLEUfoeZtzd3W0aJHN3d9f8+fMj/X4xjUEoAAAAAAAAAAAAAAAAvHf27NmjNWvWGOIpUqTQ+PHj1b59e9PnpkyZEqU+o0eP1o0bNwzxJEmSaPv27apTp46cnJxsWitdunSm19ldvXpVixYtCvvs5+en69e
"text/plain": [
"<Figure size 2400x1800 with 4 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"mpl.rcParams['figure.figsize'] = (8, 6)\n",
"\n",
"result = seasonal_decompose(df)\n",
"result.plot()\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "42a8a192-e6b4-43e1-a817-5bd44c532333",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAA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uu++O9957ryOnBQAAAEAThAMAAABosfnz58ezzz7b4NxnP/vZOPfccxuc27x5c9x+++0dOTUAAAAAmiAcAAAAQIttXTWgpKQkJk6cGKeeemr069dvm9cCAAAA0PG65XsCAAAAdC5NVQM47rjjYu+9946IiH/7t3+L6667ru57W6oMDBs2rCOn2emsXr065s2bF6tXr47Vq1dH165do1+/ftG/f/8YOXJk9O7dO2fPrqmpiWeeeSaWLVsWa9eujXfffTe6desWvXv3jkGDBsWQIUNi4MCB7fKs9evXxz/+8Y9YuXJlrFmzJmpqaqJfv37Rr1+/OOKII2K33XZrl+dsSyaTiRdeeCGef/75eOutt6KioiLKy8vjgx/8YHz84x9v8XipVCrmzZsXL7/8cqxduzaqqqpixx13jJEjR8ZRRx2V9Tgvv/xyvPzyy7F69epYu3ZtlJWVxW677RZ77bVXHHXUUVFeXt7iueXCunXr4qWXXopXXnkl1q1bFxs3bowddtgh+vbtG/37948jjzwy+vbtm+9p5lwh/CxHRDz//POxcOHCWLlyZdTU1MSuu+4ae+21VxxzzDHRs2fPDpkDAADQSWQAAACgBWbMmJGJiAZf06dPr/v+woULG33/61//equedeWVVzYaqzWWLl3aaJxbbrmlyWs//OEPN7q2pV/Njb21ioqKzNSpUzOHH354pqSkpNnxunXrljn22GMzN998c6a6urpVfwZNueeeezLjxo3L9OnTZ7trGjhwYOb888/PPPHEEy1+Tjqdztx4442ZY445JtO1a9dmn1FSUpIZMWJE5qc//WmmsrKyxc/Z3t/z2rVrM9/+9rczAwYMaPL5e++9d4PxbrnllkbXLF26tO77zz//fOazn/1spmfPnk2Od+655253zi+//HLmggsuyOy9997b/PMvLy/PfPSjH808/PDDLf5zyWQyjcbPZm5bbN68OXP33XdnvvSlL2UGDx683Z+VkpKSzEEHHZT5yU9+knn//fezfs65557b5n97V155ZZNjt9fvkkL5Wa6srMxce+21mUGDBjU7h+7du2fOPPPMzOLFi1u1VgAAIHm0FQAAAKBFtm4TsMMOO8QnP/nJuuNDDz00DjnkkAbX/Pa3v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YY46Jk046Kfbcc8/o0aNHvPnmm7Fw4cKsAhM33XRTXH/99XXHvXr1ilNOOSWOPvro6N+/f2QymXj99dfj0Ucfja5duza6f/HixXHMMcfEunXrGn3vyCOPjKOPPjoOOOCA2HnnnSOVSsXbb78ds2fPjgcffLBB9Y2VK1fGaaedFgsWLIi99tqrNX80rXLAAQfEsGHDYsiQIfGBD3wgdtxxx+jevXu8//77sWLFili4cGH86U9/is2bN9fdk8lk4jvf+U4cfPDB8bGPfazZsQcOHFj37+vdd9+N119/vcH3hwwZEt27d9/m/AYMGNCG1TWtUH6W33jjjbjkkkvqwhrdunWL448/Pk444YTYY489ory8PN5+++149NFH4/77728UPLnooovilFNOiUGDBrXq+QAAQALkqZ0BAAAAnUx1dXVm9913b9DTevfdd8/U1NQ0ef1pp53W4NouXbpkli9f3qJntlef8O31787187f429/+1mSf8mOOOSbz8ssvN3vf7NmzMwceeGCj+3baaaes/0xnzZrVZF/yQw89NKs+9mvXrs3cdNNNmUMOOWS7/epfeeWVTK9evRo960Mf+lDm73//e7P3LV68ODNy5MhG95WWlmaefvrp7c6xqb/n+n/exx9/fOaFF15o9v7Nmzc3OL7lllu2Od4FF1yQWbt2bdbjbdy4MTN
"text/plain": [
"<Figure size 2400x1500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(figsize = (8,5))\n",
"\n",
"plot_acf(df, ax = ax)\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "3d8cb39f-9e4a-47c5-a86f-630313f3d364",
"metadata": {},
"outputs": [],
"source": [
"#Loading the pandas dataframe to a TimeSeries object as required by the Darts library\n",
"series = TimeSeries.from_dataframe(df)\n",
"\n",
"start = pd.Timestamp('123115')\n"
]
},
{
"cell_type": "markdown",
"id": "a115a376-fbd7-4b1a-82ea-7a9e4d215262",
"metadata": {},
"source": [
"### Creating Utility Functions"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "828d8a5b-bd87-4a18-a544-4210574f7ce6",
"metadata": {},
"outputs": [],
"source": [
"def plot_backtest(series, forecast, model_name):\n",
" idx = -144\n",
" series[idx:].plot(label='Actual Values')\n",
" forecast[idx:].plot(label= 'Forecast')\n",
" plt.title(model_name)\n",
" plt.show()\n",
" \n",
"def print_metrics(series, forecast, model_name):\n",
" mae_ = mae(series, forecast)\n",
" rmse_ = rmse(series, forecast)\n",
" mape_ = mape(series, forecast)\n",
" smape_ = smape(series, forecast)\n",
" r2_score_ = r2_score(series, forecast)\n",
" \n",
" dict_ = {'MAE': mae_, 'RMSE': rmse_,\n",
" 'MAPE': mape_, 'SMAPE': smape_, \n",
" 'R2': r2_score_}\n",
" \n",
" df = pd.DataFrame(dict_, index = [model_name])\n",
" \n",
" return(df.round(decimals = 2)) \n",
" "
]
},
{
"cell_type": "markdown",
"id": "f8f3df4b-ee77-4a33-94db-b4df84034090",
"metadata": {},
"source": [
"### Creating a Naive Forecasting Model"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "23b13524-57dd-4ee8-90f6-132cfcf7b107",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2ed4aa9eb30042b18a28e5a42603ba37",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/62 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB98AAAV3CAYAAAD4ta+LAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/TGe4hAAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdZ3RUVfv38d+kEwihE3qX3rsoRZCiIkoRBaXdKooK3DZuQKkKiqJiwS5FUJAmKEV6k95CCRBCr4FAQktP5nnBw/w5mWRKMpkUvp+1WIu9z3X2vpIZxpjr7L1NZrPZLAAAAAA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1lX16tVVokQJBQQEyMfHRzdv3tSZM2e0d+9erVy5UjExMZZ7zGazRowYodq1a+vxxx/PlLwGDBigL7/80tA3ffp01a9f3+mxYmJi9Mcffxj6mjVrpmrVqtm8LyQkRA899JAiIyOtrjVp0kQtWrRQ1apVVbBgQcXHx+vixYvasmWLli9frri4OEvspUuX9Nhjj2nPnj0qU6aM0/k76sEHH7Tqu3btml566SX9+uuvbjnzW7pTHG7durX27Nljda1SpUpq06aN6tSpo0KFCsnLy0sRERHauXOnli1bpitXrlhiExIS9OKLL6p48eLpep8FBQWpYcOGql69usqXL6/8+fPL399ft2/f1uXLl3XgwAGtWLHCarv+v//+WyNGjNCkSZPszhEXF6fnn3/e6gEDk8mk5s2b66GHHlKlSpWUP39+eXp66saNG7p69apCQkIUHBys4OBgm7s
"text/plain": [
"<Figure size 2400x1500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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>MAE</th>\n",
" <th>RMSE</th>\n",
" <th>MAPE</th>\n",
" <th>SMAPE</th>\n",
" <th>R2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Naive Seasonal</th>\n",
" <td>2.4</td>\n",
" <td>2.45</td>\n",
" <td>0.58</td>\n",
" <td>0.59</td>\n",
" <td>0.64</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" MAE RMSE MAPE SMAPE R2\n",
"Naive Seasonal 2.4 2.45 0.58 0.59 0.64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_metrics = pd.DataFrame()\n",
"\n",
"model = NaiveSeasonal(K = 12)\n",
"model_name = 'Naive Seasonal'\n",
"\n",
"plt.figure(figsize = (8, 5))\n",
"\n",
"forecast = model.historical_forecasts(series, start=start, forecast_horizon=12, verbose=True)\n",
"plot_backtest(series, forecast, model_name)\n",
"df_naive = print_metrics(series, forecast, model_name)\n",
"df_metrics = df_naive\n",
"\n",
"plt.show()\n",
"df_naive"
]
},
{
"cell_type": "markdown",
"id": "94065558-d62f-47fd-8d9b-33ce7f7044a9",
"metadata": {},
"source": [
"### Creating an Exponential Smoothing Forecasting Model"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "fe9a5ef1-0d07-4e25-b8bf-251ea3e05bee",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "486fc85982cb4c22834d1f090ec3eaf7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/62 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB98AAAV3CAYAAAD4ta+LAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/TGe4hAAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdd3iUxdrH8d+mkUIoIYQmvfeOKCJVUSkKSFFpooi9HvWAHuoRKwqCYqcIiNRDFQWkQ+g9tCBIDwRCIL097x95WdnsZkt6+X6ui+tiZu+ZuTcJD8q9M2MyDMMQAAAAAAAAAAAAAADIMLfcTgAAAAAAAAAAAAAAgPyO4jsAAAAAAAAAAAAAAJlE8R0AAAAAAAAAAAAAgEyi+A4AAAAAAAAAAAAAQCZRfAcAAAAAAAAAAAAAIJMovgMAAAAAAAAAAAAAkEkU3wEAAAAAAAAAAAAAyCSK7wAAAAAAAAAAAAAAZBLFdwAAAAAAAAA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OZgMpmM+vXrG5999plx69Ytp9e5k6M/c9nB1ns7fvx4tq6ZVtr1R48ebX4tNjbW+Oijj4yKFSum+7UvVaqUMWrUKCMmJibdNcLCwow333zTKFWqVLrzVK1a1Zg+fbqRkpKS6fd0/Phx45lnnjHKli1r9+emVKlSxpNPPmns3bs302veNn/+fOOBBx4wihQpYnft+vXrG6NHjzYiIyOdmtfW34MZ+WWLo5/9yMhIY9SoUUaZMmXSndfPz88YMmSIcfbsWZe/ZtOnT3f6uXKnwYMHW4ypXLmyxev79u0zevfubXh6eqabd+XKlY0pU6YYCQkJLued1tKlS4127doZbm5u6a7XpEkTY9asWRY/5+3atbOIyYn/vgEAAADSovgOAAAAFCK5VXy/efOmzeLY999/79I8s2bNslloioiISHeMvWLITz/9ZPj4+DhdbKlUqZKxdu3aDH8dTp06ZTz44IMuF3n8/PyMcePGGcnJyS6tl17R9saNG0b37t1dymHw4MFGYmJiht/7pk2bjGbNmrn83osUKWL85z//cem92yu+T5061fD29nZ6/SpVqhgnTpxwuGZWFPOyuvg+adIko1ixYhnOp2TJksaiRYucWutOuVF8b9SokdWaf/zxR7aumVba9W8X30NCQpz64MPtX/Xr1zf+/vtvq/mXLl1qBAQEOD1P9+7djfj4+Ay9l+joaOOFF14wPDw8XPqZMZlMxoABA4zr169n+Ou4d+9eo2XLli7/vAYGBhrffPONw/lzq/i+adMmo0KFCk7P7+PjYyxdutSlr11WF99TUlKM999/33B3d3c676ZNmxphYWEu5X1beHi48eijj7r0fWjfvr1x9epVwzAovgMAACBv4M53AAAAANnO399fCxYskLe3t0X/q6++qoMHDzo1x9GjR/XCCy9Y9Hl5eenXX39ViRIlXM5p2rRpGjp0qGJjY50ec/bsWT3yyCNauXKly+vt2bNH9957r/744w+Xx0ZHR2vUqFHq16+f4uPjXR5/p2vXrum+++7T8uXLXRo3c+ZMDRkyJENrfvfdd+rYsaP27t3r8tj4+HiNHz9ePXv2VHR0dIbWv23kyJF6+eWXFRcX5/SYM2fO6L777tOFCxcytXZu2Ldvn27evJnh8REREXr88cf10UcfZWFW2aNs2bJWffPnz8+FTCwdPnxYbdq00YkTJ5wec+TIEXXp0sXiezdjxgz17NlT169fd3qe5cuX68knn3QpX0kKDw9Xx44dNW3aNCUlJbk01jAMzZ49W/fdd5/Onj3r8tqrV69W27ZttWvXLpfHhoeH6/nnn9drr72mlJQUl8dnpxUrVqhz584uPUdiY2PVu3dvrV69OhszS19KSooGDhyo//73v0pOTnZ63L59+3T//fcrKir
"text/plain": [
"<Figure size 2400x1500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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>MAE</th>\n",
" <th>RMSE</th>\n",
" <th>MAPE</th>\n",
" <th>SMAPE</th>\n",
" <th>R2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Exponential Smoothing</th>\n",
" <td>0.41</td>\n",
" <td>0.53</td>\n",
" <td>0.1</td>\n",
" <td>0.1</td>\n",
" <td>0.98</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" MAE RMSE MAPE SMAPE R2\n",
"Exponential Smoothing 0.41 0.53 0.1 0.1 0.98"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = ExponentialSmoothing(seasonal_periods = 12)\n",
"model_name = 'Exponential Smoothing'\n",
"\n",
"plt.figure(figsize = (8, 5))\n",
"\n",
"forecast = model.historical_forecasts(series, start=start, forecast_horizon=12, verbose=True)\n",
"plot_backtest(series, forecast, model_name)\n",
"df_exp = print_metrics(series, forecast, model_name)\n",
"df_metrics = pd.concat([df_metrics, df_exp])\n",
"\n",
"plt.show()\n",
"df_exp"
]
},
{
"cell_type": "markdown",
"id": "4c496bec-cc3b-4c17-8700-d5b55673852e",
"metadata": {},
"source": [
"### Creating a Linear Regression Forecasting Model"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "56bca3f8-aa97-406e-80c3-5b928889f5fe",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "faffaee45f774b9cb61df50d9129e9a0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
" 0%| | 0/62 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB98AAAV3CAYAAAD4ta+LAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/TGe4hAAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdd3RUVdfH8d+kAQklBAgldKT3DtIRRRQbIAgqYAEUBFQUxQ48oth5VGyPAlJEpQgCIkVAEAIECcXQQq+hpZDe7vtHXkZuZjIz6YXvZ62slXPm3HP2TCYjZt+zj8UwDEMAAAAAAAAAAAAAACDL3PI7AAAAAAAAAAAAAAAACjuS7wAAAAAAAAAAAAAAZBPJdwAAAAAAAAAAAAAAsonkOwAAAAAAAAAAAAAA2UTyHQAAAAAAAAAAAACAbCL5DgAAAAAAAAAAAABANpF8BwAAAAAAAAAAAAAgm0i+AwAAAAAAAAAAAACQTSTfAQAAAAAAAAAAAADIJpLvAAAAAAAAAAAAAABkE8l3AAAAAAAAAAAAAACyieQ7AAAAAAAAAAAAAADZRPIdAAAAAAAAAAAAAIBsIvkOAAAAAAAAAAAAAEA2kXwHAAAAAAAAAAAAACCbSL4DAAAAAAAAAAAAAJBNJN8BAAAAAAAAAAAAAMgmku8AAAAAAAAA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qyHHnpILVq00P79+zO13nVXrlzR/fffr/vuu0+bNm1SampqhmODg4M1dOhQ9ezZU5cvX87Ses58++23atiwoT7//HOFh4dn+vq8fh3Dw8PVr18/9ezZUz/++KPi4uJcuu7y5ctasWKFRo4cqWeeecbp+ISEBI0aNUrt2rXTt99+q8jISJfWiYqK0rp16/Tcc89pwIABLl2TXevXr1eTJk00cuRIbdmyxeHvtGEYCgoK0oQJE1SvXj0tXbo0x+IICQlRixYt9Pzzz+vEiRMZjktMTNTSpUvVtGlTffnllzm2PgAAAIDsI/kOAAAAAIVUamqqHn30Uf3nP//JVAJ49+7d6tq1q6KjozO9ZmBgoNq1a6clS5Zk+lpJWrJkiTp06KDQ0FCXr9mxY4fi4+OztJ4knTlzRrfddpvmzp2b5Tmui4mJ0W233abFixdne678ZO8GCHvnwGfkwoUL6t69uz744IMs/Wz27t2rW2+9VatWrcrUdZcvX1bPnj21bNmyTF23ceNGde3aNUvJcUfef/99Pfnkk4qNjc3S9Xn9OoaHh6t79+45mjC2JzExUXfffbe+/vprhzdHFASzZs3SnXfeqUOHDmX62lOnTql///56//33sx3Hzp071bFjR6c3X9woJSVFTz/9tL755ptsrw8AAAAgZ3DmOwAAAAAUUq+++qrmz59vbVerVk133323mjZtqvLlyys6OloHDhzQ4sWLdfz4cdO1hw4d0ssvv6zPPvvM5fU2btyoPn362CQJ3dzc1KVLF916662qVauWfH19FRcXpzNnzmjTpk1av3696eaAQ4cO6a677lJQUJBKly6dqedssVjUtGlTNW3aVA0bNlSFChVUunRpubu769q1azp27Jh27typDRs2mKoAJCUlacSIEWrSpIlatmyZqTVvNHLkSO3YscParlKlivU19/f3V1RUlE6ePKnly5dneY28sHfvXpu+OnXquHRtWFiYOnTooJMnT9o81qRJE3Xr1k2NGzeWr6+vpLQz2bdt26ZVq1bp2rVr1rHXrl1T//79tXXrVpd+JsnJyerTp4/d2CtXrqz7779fTZo0Ufny5XX16lUdOnRIy5Yts773Dxw4oKFDh7r0HF2xZs0avfvuu9Z2sWLF1KNHD3Xv3l2VKlWSh4eHzpw5o+3bt9u90SU/Xsfnn3/e7utXr14
"text/plain": [
"<Figure size 2400x1500 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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>MAE</th>\n",
" <th>RMSE</th>\n",
" <th>MAPE</th>\n",
" <th>SMAPE</th>\n",
" <th>R2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Linear Regression</th>\n",
" <td>0.44</td>\n",
" <td>0.54</td>\n",
" <td>0.11</td>\n",
" <td>0.11</td>\n",
" <td>0.98</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" MAE RMSE MAPE SMAPE R2\n",
"Linear Regression 0.44 0.54 0.11 0.11 0.98"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = LinearRegressionModel(lags = 12)\n",
"model_name = 'Linear Regression'\n",
"\n",
"plt.figure(figsize = (8, 5))\n",
"\n",
"forecast = model.historical_forecasts(series, start=start, forecast_horizon=12, verbose=True)\n",
"plot_backtest(series, forecast, model_name)\n",
"df_lr = print_metrics(series, forecast, model_name)\n",
"df_metrics = pd.concat([df_metrics, df_lr])\n",
"\n",
"plt.show()\n",
"df_lr"
]
},
{
"cell_type": "markdown",
"id": "62d100d4-a879-48c4-b172-5b91baf31cb3",
"metadata": {},
"source": [
"### Creating a DL Forecasting Model"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33d61373-2f55-4286-ab2d-67379408de6a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# не заработало, уходит в цикл\n",
"\n",
"model = TCNModel(\n",
" input_chunk_length=24,\n",
" output_chunk_length=12,\n",
" n_epochs=100,\n",
" dropout=0.1,\n",
" dilation_base=3,\n",
" weight_norm=True,\n",
" kernel_size=5,\n",
" num_filters=3,\n",
" random_state=0,\n",
")\n",
"\n",
"model_name = 'TCN'\n",
"\n",
"plt.figure(figsize = (8, 5))\n",
"\n",
"scaler = Scaler()\n",
"scaled_series = scaler.fit_transform(series)\n",
"forecast = model.historical_forecasts(scaled_series, start=start,\n",
" forecast_horizon=12, verbose=True)\n",
"plot_backtest(series, scaler.inverse_transform(forecast), model_name)\n",
"df_dl = print_metrics(series, scaler.inverse_transform(forecast), model_name)\n",
"df_metrics = pd.concat([df_metrics, df_dl])\n",
"\n",
"plt.show()\n",
"df_dl"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "450232c3-5506-4dc2-a529-85c43560e2ed",
"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>MAE</th>\n",
" <th>RMSE</th>\n",
" <th>MAPE</th>\n",
" <th>SMAPE</th>\n",
" <th>R2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Naive Seasonal</th>\n",
" <td>2.40</td>\n",
" <td>2.45</td>\n",
" <td>0.58</td>\n",
" <td>0.59</td>\n",
" <td>0.64</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Exponential Smoothing</th>\n",
" <td>0.41</td>\n",
" <td>0.53</td>\n",
" <td>0.10</td>\n",
" <td>0.10</td>\n",
" <td>0.98</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Linear Regression</th>\n",
" <td>0.44</td>\n",
" <td>0.54</td>\n",
" <td>0.11</td>\n",
" <td>0.11</td>\n",
" <td>0.98</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" MAE RMSE MAPE SMAPE R2\n",
"Naive Seasonal 2.40 2.45 0.58 0.59 0.64\n",
"Exponential Smoothing 0.41 0.53 0.10 0.10 0.98\n",
"Linear Regression 0.44 0.54 0.11 0.11 0.98"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_metrics"
]
},
{
"cell_type": "markdown",
"id": "c3a93001-9d3d-4d2e-b302-28c93aa19220",
"metadata": {},
"source": [
"### Creating a Forecast"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "d365c4c1-1771-4fde-80ac-9b44875daa49",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAB98AAAZeCAYAAADp/uHoAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/TGe4hAAAACXBIWXMAAC4jAAAuIwF4pT92AAEAAElEQVR4nOzdd3RVVfr/8c9NSCeUEEKH0CEgvYr0JlIUERCliSIqgqgzOoAD9oaMDbHOgAUEEZAqCkhAegchtCAQaiAQWkjP+f3Bj/vl5N7ckh7yfq2Vtdj77PLckoPynL23xTAMQwAAAAAAAAAAAAAAINM88joAAAAAAAAAAAAAAAAKOpLvAAAAAAAAAAAAAABkEcl3AAAAAAAAAAAAAACyiOQ7AAAAAAAAAAAAAABZRPIdAAAAAAAAAAAAAIAsIvkOAAAAAAAAAAAAAEAWkXwHAAAAAAAAAAAAACCLSL4DAAAAAAAAAAAAAJBFJN8BAAAAAAAAAAAAAMgiku8AAAAAAAAAAAAAAGQRyXcAAAAAAAAAAAAAALKI5DsAAAAAAAA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t2ujw4cMu99m/f7+6d+9u+uxmzpypvn376tKlSy6Ps2TJEj3yyCNuxStJMTEx6tSpkz7//HOlpKS41dcwDP3www+65557FBUV5fbcK1asUNu2bbVt2za3+8bExOipp57Sc889p7S0NLf756SlS5eqS5cubt1H4uPj1a9fP61YsSIHI8tYWlqahgwZojfffFOpqaku99u1a5fatWu
"text/plain": [
"<Figure size 2400x1800 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"component CO2\n",
"Datetime \n",
"2022-01-31 417.632844\n",
"2022-02-28 418.396292\n",
"2022-03-31 419.057944\n",
"2022-04-30 420.637401\n",
"2022-05-31 421.450293\n",
"2022-06-30 420.702140\n",
"2022-07-31 418.846186\n",
"2022-08-31 416.877530\n",
"2022-09-30 415.416156\n",
"2022-10-31 415.689644\n",
"2022-11-30 417.336950\n",
"2022-12-31 418.695037\n"
]
}
],
"source": [
"model = ExponentialSmoothing(seasonal_periods = 12)\n",
"model_name = 'Exponential Smoothing'\n",
"\n",
"model.fit(series)\n",
"forecast = model.predict(12)\n",
"\n",
"plot_backtest(series, forecast, model_name)\n",
"print(forecast.pd_dataframe())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}