ibnummuhammad commited on
Commit
f930178
1 Parent(s): bc7c2f9

Add box_cox.ipynb

Browse files
autoregression.ipynb CHANGED
@@ -1231,23 +1231,28 @@
1231
  "import pandas as pd\n",
1232
  "\n",
1233
  "# Read in the data\n",
1234
- "data = pd.read_csv('../coal-price-data/AirPassengers.csv')\n",
1235
- "data['Month'] = pd.to_datetime(data['Month'])\n",
1236
  "\n",
1237
  "\n",
1238
- "def plot_passenger_volumes(df: pd.DataFrame,\n",
1239
- " y: str) -> None:\n",
1240
  " \"\"\"General function to plot the passenger data.\"\"\"\n",
1241
  "\n",
1242
- " fig = px.line(df, x='Month', y=y, labels={'Month': 'Date'})\n",
1243
- " fig.update_layout(template=\"simple_white\", font=dict(size=18), title_text='Airline Passengers',\n",
1244
- " width=650, title_x=0.5, height=400)\n",
 
 
 
 
 
 
1245
  "\n",
1246
  " return fig.show()\n",
1247
  "\n",
1248
  "\n",
1249
  "# Plot the airline passenger data\n",
1250
- "plot_passenger_volumes(df=data, y='#Passengers')"
1251
  ]
1252
  },
1253
  {
@@ -2478,12 +2483,12 @@
2478
  "from scipy.stats import boxcox\n",
2479
  "\n",
2480
  "# Make the target stationary\n",
2481
- "data['Passengers_boxcox'], lam = boxcox(data['#Passengers'])\n",
2482
  "data[\"Passenger_stationary\"] = data[\"Passengers_boxcox\"].diff()\n",
2483
  "data.dropna(inplace=True)\n",
2484
  "\n",
2485
  "# Plot the stationary airline passenger data\n",
2486
- "plot_passenger_volumes(df=data, y='Passenger_stationary')"
2487
  ]
2488
  },
2489
  {
@@ -2509,15 +2514,16 @@
2509
  "# Import packages\n",
2510
  "from statsmodels.tsa.stattools import adfuller\n",
2511
  "\n",
 
2512
  "# ADF test for stationary\n",
2513
  "def adf_test(series):\n",
2514
  " \"\"\"Using an ADF test to determine if a series is stationary\"\"\"\n",
2515
  " test_results = adfuller(series)\n",
2516
- " print('ADF Statistic: ', test_results[0])\n",
2517
- " print('P-Value: ', test_results[1])\n",
2518
- " print('Critical Values:')\n",
2519
  " for threshold, adf_stat in test_results[4].items():\n",
2520
- " print('\\t%s: %.2f' % (threshold, adf_stat))\n",
2521
  "\n",
2522
  "\n",
2523
  "print(adf_test(data[\"Passenger_stationary\"]))"
@@ -2686,13 +2692,13 @@
2686
  "from statsmodels.graphics.tsaplots import plot_pacf\n",
2687
  "\n",
2688
  "# Plot partial autocorrelation\n",
2689
- "plt.rc(\"figure\", figsize=(11,5))\n",
2690
- "plot_pacf(data['Passenger_stationary'], method='ywm')\n",
2691
- "plt.xlabel('Lags', fontsize=18)\n",
2692
- "plt.ylabel('Correlation', fontsize=18)\n",
2693
  "plt.xticks(fontsize=18)\n",
2694
  "plt.yticks(fontsize=18)\n",
2695
- "plt.title('Partial Autocorrelation Plot', fontsize=20)\n",
2696
  "plt.tight_layout()\n",
2697
  "plt.show()"
2698
  ]
@@ -2726,12 +2732,12 @@
2726
  "from statsmodels.tsa.ar_model import AutoReg, ar_select_order\n",
2727
  "\n",
2728
  "# Split train and test\n",
2729
- "train = data.iloc[:-int(len(data) * 0.2)]\n",
2730
- "test = data.iloc[-int(len(data) * 0.2):]\n",
2731
  "\n",
2732
  "# Build AR model\n",
2733
- "selector = ar_select_order(train['Passenger_stationary'], 15)\n",
2734
- "model = AutoReg(train['Passenger_stationary'], lags=selector.ar_lags).fit()"
2735
  ]
2736
  },
2737
  {
@@ -4023,31 +4029,43 @@
4023
  "boxcox_forecasts = []\n",
4024
  "for idx in range(len(test)):\n",
4025
  " if idx == 0:\n",
4026
- " boxcox_forecast = transformed_forecasts[idx] + train['Passengers_boxcox'].iloc[-1]\n",
 
 
4027
  " else:\n",
4028
- " boxcox_forecast = transformed_forecasts[idx] + boxcox_forecasts[idx-1]\n",
4029
  "\n",
4030
  " boxcox_forecasts.append(boxcox_forecast)\n",
4031
  "\n",
4032
  "forecasts = inv_boxcox(boxcox_forecasts, lam)\n",
4033
  "\n",
4034
  "\n",
4035
- "def plot_forecasts(forecasts: list[float],\n",
4036
- " title: str) -> None:\n",
4037
  " \"\"\"Function to plot the forecasts.\"\"\"\n",
4038
  " fig = go.Figure()\n",
4039
- " fig.add_trace(go.Scatter(x=train['Month'], y=train['#Passengers'], name='Train'))\n",
4040
- " fig.add_trace(go.Scatter(x=test['Month'], y=test['#Passengers'], name='Test'))\n",
4041
- " fig.add_trace(go.Scatter(x=test['Month'], y=forecasts, name='Forecast'))\n",
4042
- " fig.update_layout(template=\"simple_white\", font=dict(size=18), title_text=title,\n",
4043
- " width=650, title_x=0.5, height=400, xaxis_title='Date',\n",
4044
- " yaxis_title='Passenger Volume')\n",
 
 
 
 
 
 
 
 
 
 
 
4045
  "\n",
4046
  " return fig.show()\n",
4047
  "\n",
4048
  "\n",
4049
  "# Plot the forecasts\n",
4050
- "plot_forecasts(forecasts, 'Autoregression')"
4051
  ]
4052
  },
4053
  {
 
1231
  "import pandas as pd\n",
1232
  "\n",
1233
  "# Read in the data\n",
1234
+ "data = pd.read_csv(\"../coal-price-data/AirPassengers.csv\")\n",
1235
+ "data[\"Month\"] = pd.to_datetime(data[\"Month\"])\n",
1236
  "\n",
1237
  "\n",
1238
+ "def plot_passenger_volumes(df: pd.DataFrame, y: str) -> None:\n",
 
1239
  " \"\"\"General function to plot the passenger data.\"\"\"\n",
1240
  "\n",
1241
+ " fig = px.line(df, x=\"Month\", y=y, labels={\"Month\": \"Date\"})\n",
1242
+ " fig.update_layout(\n",
1243
+ " template=\"simple_white\",\n",
1244
+ " font=dict(size=18),\n",
1245
+ " title_text=\"Airline Passengers\",\n",
1246
+ " width=650,\n",
1247
+ " title_x=0.5,\n",
1248
+ " height=400,\n",
1249
+ " )\n",
1250
  "\n",
1251
  " return fig.show()\n",
1252
  "\n",
1253
  "\n",
1254
  "# Plot the airline passenger data\n",
1255
+ "plot_passenger_volumes(df=data, y=\"#Passengers\")"
1256
  ]
1257
  },
1258
  {
 
2483
  "from scipy.stats import boxcox\n",
2484
  "\n",
2485
  "# Make the target stationary\n",
2486
+ "data[\"Passengers_boxcox\"], lam = boxcox(data[\"#Passengers\"])\n",
2487
  "data[\"Passenger_stationary\"] = data[\"Passengers_boxcox\"].diff()\n",
2488
  "data.dropna(inplace=True)\n",
2489
  "\n",
2490
  "# Plot the stationary airline passenger data\n",
2491
+ "plot_passenger_volumes(df=data, y=\"Passenger_stationary\")"
2492
  ]
2493
  },
2494
  {
 
2514
  "# Import packages\n",
2515
  "from statsmodels.tsa.stattools import adfuller\n",
2516
  "\n",
2517
+ "\n",
2518
  "# ADF test for stationary\n",
2519
  "def adf_test(series):\n",
2520
  " \"\"\"Using an ADF test to determine if a series is stationary\"\"\"\n",
2521
  " test_results = adfuller(series)\n",
2522
+ " print(\"ADF Statistic: \", test_results[0])\n",
2523
+ " print(\"P-Value: \", test_results[1])\n",
2524
+ " print(\"Critical Values:\")\n",
2525
  " for threshold, adf_stat in test_results[4].items():\n",
2526
+ " print(\"\\t%s: %.2f\" % (threshold, adf_stat))\n",
2527
  "\n",
2528
  "\n",
2529
  "print(adf_test(data[\"Passenger_stationary\"]))"
 
2692
  "from statsmodels.graphics.tsaplots import plot_pacf\n",
2693
  "\n",
2694
  "# Plot partial autocorrelation\n",
2695
+ "plt.rc(\"figure\", figsize=(11, 5))\n",
2696
+ "plot_pacf(data[\"Passenger_stationary\"], method=\"ywm\")\n",
2697
+ "plt.xlabel(\"Lags\", fontsize=18)\n",
2698
+ "plt.ylabel(\"Correlation\", fontsize=18)\n",
2699
  "plt.xticks(fontsize=18)\n",
2700
  "plt.yticks(fontsize=18)\n",
2701
+ "plt.title(\"Partial Autocorrelation Plot\", fontsize=20)\n",
2702
  "plt.tight_layout()\n",
2703
  "plt.show()"
2704
  ]
 
2732
  "from statsmodels.tsa.ar_model import AutoReg, ar_select_order\n",
2733
  "\n",
2734
  "# Split train and test\n",
2735
+ "train = data.iloc[: -int(len(data) * 0.2)]\n",
2736
+ "test = data.iloc[-int(len(data) * 0.2) :]\n",
2737
  "\n",
2738
  "# Build AR model\n",
2739
+ "selector = ar_select_order(train[\"Passenger_stationary\"], 15)\n",
2740
+ "model = AutoReg(train[\"Passenger_stationary\"], lags=selector.ar_lags).fit()"
2741
  ]
2742
  },
2743
  {
 
4029
  "boxcox_forecasts = []\n",
4030
  "for idx in range(len(test)):\n",
4031
  " if idx == 0:\n",
4032
+ " boxcox_forecast = (\n",
4033
+ " transformed_forecasts[idx] + train[\"Passengers_boxcox\"].iloc[-1]\n",
4034
+ " )\n",
4035
  " else:\n",
4036
+ " boxcox_forecast = transformed_forecasts[idx] + boxcox_forecasts[idx - 1]\n",
4037
  "\n",
4038
  " boxcox_forecasts.append(boxcox_forecast)\n",
4039
  "\n",
4040
  "forecasts = inv_boxcox(boxcox_forecasts, lam)\n",
4041
  "\n",
4042
  "\n",
4043
+ "def plot_forecasts(forecasts: list[float], title: str) -> None:\n",
 
4044
  " \"\"\"Function to plot the forecasts.\"\"\"\n",
4045
  " fig = go.Figure()\n",
4046
+ " fig.add_trace(\n",
4047
+ " go.Scatter(x=train[\"Month\"], y=train[\"#Passengers\"], name=\"Train\")\n",
4048
+ " )\n",
4049
+ " fig.add_trace(\n",
4050
+ " go.Scatter(x=test[\"Month\"], y=test[\"#Passengers\"], name=\"Test\")\n",
4051
+ " )\n",
4052
+ " fig.add_trace(go.Scatter(x=test[\"Month\"], y=forecasts, name=\"Forecast\"))\n",
4053
+ " fig.update_layout(\n",
4054
+ " template=\"simple_white\",\n",
4055
+ " font=dict(size=18),\n",
4056
+ " title_text=title,\n",
4057
+ " width=650,\n",
4058
+ " title_x=0.5,\n",
4059
+ " height=400,\n",
4060
+ " xaxis_title=\"Date\",\n",
4061
+ " yaxis_title=\"Passenger Volume\",\n",
4062
+ " )\n",
4063
  "\n",
4064
  " return fig.show()\n",
4065
  "\n",
4066
  "\n",
4067
  "# Plot the forecasts\n",
4068
+ "plot_forecasts(forecasts, \"Autoregression\")"
4069
  ]
4070
  },
4071
  {
box_cox.ipynb ADDED
@@ -0,0 +1,2721 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 8,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "# Import packages\n",
10
+ "import plotly.express as px\n",
11
+ "import pandas as pd\n",
12
+ "# Import the transform\n",
13
+ "from scipy.stats import boxcox"
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": 9,
19
+ "metadata": {},
20
+ "outputs": [],
21
+ "source": [
22
+ "# Read in the data\n",
23
+ "data = pd.read_csv(\"../coal-price-data/AirPassengers.csv\")"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": 2,
29
+ "metadata": {},
30
+ "outputs": [
31
+ {
32
+ "data": {
33
+ "text/html": [
34
+ "<div>\n",
35
+ "<style scoped>\n",
36
+ " .dataframe tbody tr th:only-of-type {\n",
37
+ " vertical-align: middle;\n",
38
+ " }\n",
39
+ "\n",
40
+ " .dataframe tbody tr th {\n",
41
+ " vertical-align: top;\n",
42
+ " }\n",
43
+ "\n",
44
+ " .dataframe thead th {\n",
45
+ " text-align: right;\n",
46
+ " }\n",
47
+ "</style>\n",
48
+ "<table border=\"1\" class=\"dataframe\">\n",
49
+ " <thead>\n",
50
+ " <tr style=\"text-align: right;\">\n",
51
+ " <th></th>\n",
52
+ " <th>Month</th>\n",
53
+ " <th>#Passengers</th>\n",
54
+ " </tr>\n",
55
+ " </thead>\n",
56
+ " <tbody>\n",
57
+ " <tr>\n",
58
+ " <th>0</th>\n",
59
+ " <td>1949-01</td>\n",
60
+ " <td>112</td>\n",
61
+ " </tr>\n",
62
+ " <tr>\n",
63
+ " <th>1</th>\n",
64
+ " <td>1949-02</td>\n",
65
+ " <td>118</td>\n",
66
+ " </tr>\n",
67
+ " <tr>\n",
68
+ " <th>2</th>\n",
69
+ " <td>1949-03</td>\n",
70
+ " <td>132</td>\n",
71
+ " </tr>\n",
72
+ " <tr>\n",
73
+ " <th>3</th>\n",
74
+ " <td>1949-04</td>\n",
75
+ " <td>129</td>\n",
76
+ " </tr>\n",
77
+ " <tr>\n",
78
+ " <th>4</th>\n",
79
+ " <td>1949-05</td>\n",
80
+ " <td>121</td>\n",
81
+ " </tr>\n",
82
+ " <tr>\n",
83
+ " <th>...</th>\n",
84
+ " <td>...</td>\n",
85
+ " <td>...</td>\n",
86
+ " </tr>\n",
87
+ " <tr>\n",
88
+ " <th>139</th>\n",
89
+ " <td>1960-08</td>\n",
90
+ " <td>606</td>\n",
91
+ " </tr>\n",
92
+ " <tr>\n",
93
+ " <th>140</th>\n",
94
+ " <td>1960-09</td>\n",
95
+ " <td>508</td>\n",
96
+ " </tr>\n",
97
+ " <tr>\n",
98
+ " <th>141</th>\n",
99
+ " <td>1960-10</td>\n",
100
+ " <td>461</td>\n",
101
+ " </tr>\n",
102
+ " <tr>\n",
103
+ " <th>142</th>\n",
104
+ " <td>1960-11</td>\n",
105
+ " <td>390</td>\n",
106
+ " </tr>\n",
107
+ " <tr>\n",
108
+ " <th>143</th>\n",
109
+ " <td>1960-12</td>\n",
110
+ " <td>432</td>\n",
111
+ " </tr>\n",
112
+ " </tbody>\n",
113
+ "</table>\n",
114
+ "<p>144 rows × 2 columns</p>\n",
115
+ "</div>"
116
+ ],
117
+ "text/plain": [
118
+ " Month #Passengers\n",
119
+ "0 1949-01 112\n",
120
+ "1 1949-02 118\n",
121
+ "2 1949-03 132\n",
122
+ "3 1949-04 129\n",
123
+ "4 1949-05 121\n",
124
+ ".. ... ...\n",
125
+ "139 1960-08 606\n",
126
+ "140 1960-09 508\n",
127
+ "141 1960-10 461\n",
128
+ "142 1960-11 390\n",
129
+ "143 1960-12 432\n",
130
+ "\n",
131
+ "[144 rows x 2 columns]"
132
+ ]
133
+ },
134
+ "execution_count": 2,
135
+ "metadata": {},
136
+ "output_type": "execute_result"
137
+ }
138
+ ],
139
+ "source": [
140
+ "data"
141
+ ]
142
+ },
143
+ {
144
+ "cell_type": "code",
145
+ "execution_count": 3,
146
+ "metadata": {},
147
+ "outputs": [
148
+ {
149
+ "data": {
150
+ "text/plain": [
151
+ "0 1949-01\n",
152
+ "1 1949-02\n",
153
+ "2 1949-03\n",
154
+ "3 1949-04\n",
155
+ "4 1949-05\n",
156
+ " ... \n",
157
+ "139 1960-08\n",
158
+ "140 1960-09\n",
159
+ "141 1960-10\n",
160
+ "142 1960-11\n",
161
+ "143 1960-12\n",
162
+ "Name: Month, Length: 144, dtype: object"
163
+ ]
164
+ },
165
+ "execution_count": 3,
166
+ "metadata": {},
167
+ "output_type": "execute_result"
168
+ }
169
+ ],
170
+ "source": [
171
+ "data[\"Month\"]"
172
+ ]
173
+ },
174
+ {
175
+ "cell_type": "code",
176
+ "execution_count": 4,
177
+ "metadata": {},
178
+ "outputs": [],
179
+ "source": [
180
+ "# def plotting(title, data, x, y, x_label, y_label, text=False, lam=None):\n",
181
+ "title=\"Airline Passengers\"\n",
182
+ "data=data\n",
183
+ "x=\"Month\"\n",
184
+ "y=\"#Passengers\"\n",
185
+ "x_label=\"Date\"\n",
186
+ "y_label=\"Passengers\"\n",
187
+ "text=False\n",
188
+ "lam=None"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": 5,
194
+ "metadata": {},
195
+ "outputs": [],
196
+ "source": [
197
+ "\"\"\"General function to plot the passenger data.\"\"\"\n",
198
+ "fig = px.line(data, x=data[x], y=data[y], labels={x: x_label, y: y_label})"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "execution_count": 6,
204
+ "metadata": {},
205
+ "outputs": [
206
+ {
207
+ "data": {
208
+ "application/vnd.plotly.v1+json": {
209
+ "config": {
210
+ "plotlyServerURL": "https://plot.ly"
211
+ },
212
+ "data": [
213
+ {
214
+ "hovertemplate": "Date=%{x}<br>Passengers=%{y}<extra></extra>",
215
+ "legendgroup": "",
216
+ "line": {
217
+ "color": "#636efa",
218
+ "dash": "solid"
219
+ },
220
+ "marker": {
221
+ "symbol": "circle"
222
+ },
223
+ "mode": "lines",
224
+ "name": "",
225
+ "orientation": "v",
226
+ "showlegend": false,
227
+ "type": "scatter",
228
+ "x": [
229
+ "1949-01",
230
+ "1949-02",
231
+ "1949-03",
232
+ "1949-04",
233
+ "1949-05",
234
+ "1949-06",
235
+ "1949-07",
236
+ "1949-08",
237
+ "1949-09",
238
+ "1949-10",
239
+ "1949-11",
240
+ "1949-12",
241
+ "1950-01",
242
+ "1950-02",
243
+ "1950-03",
244
+ "1950-04",
245
+ "1950-05",
246
+ "1950-06",
247
+ "1950-07",
248
+ "1950-08",
249
+ "1950-09",
250
+ "1950-10",
251
+ "1950-11",
252
+ "1950-12",
253
+ "1951-01",
254
+ "1951-02",
255
+ "1951-03",
256
+ "1951-04",
257
+ "1951-05",
258
+ "1951-06",
259
+ "1951-07",
260
+ "1951-08",
261
+ "1951-09",
262
+ "1951-10",
263
+ "1951-11",
264
+ "1951-12",
265
+ "1952-01",
266
+ "1952-02",
267
+ "1952-03",
268
+ "1952-04",
269
+ "1952-05",
270
+ "1952-06",
271
+ "1952-07",
272
+ "1952-08",
273
+ "1952-09",
274
+ "1952-10",
275
+ "1952-11",
276
+ "1952-12",
277
+ "1953-01",
278
+ "1953-02",
279
+ "1953-03",
280
+ "1953-04",
281
+ "1953-05",
282
+ "1953-06",
283
+ "1953-07",
284
+ "1953-08",
285
+ "1953-09",
286
+ "1953-10",
287
+ "1953-11",
288
+ "1953-12",
289
+ "1954-01",
290
+ "1954-02",
291
+ "1954-03",
292
+ "1954-04",
293
+ "1954-05",
294
+ "1954-06",
295
+ "1954-07",
296
+ "1954-08",
297
+ "1954-09",
298
+ "1954-10",
299
+ "1954-11",
300
+ "1954-12",
301
+ "1955-01",
302
+ "1955-02",
303
+ "1955-03",
304
+ "1955-04",
305
+ "1955-05",
306
+ "1955-06",
307
+ "1955-07",
308
+ "1955-08",
309
+ "1955-09",
310
+ "1955-10",
311
+ "1955-11",
312
+ "1955-12",
313
+ "1956-01",
314
+ "1956-02",
315
+ "1956-03",
316
+ "1956-04",
317
+ "1956-05",
318
+ "1956-06",
319
+ "1956-07",
320
+ "1956-08",
321
+ "1956-09",
322
+ "1956-10",
323
+ "1956-11",
324
+ "1956-12",
325
+ "1957-01",
326
+ "1957-02",
327
+ "1957-03",
328
+ "1957-04",
329
+ "1957-05",
330
+ "1957-06",
331
+ "1957-07",
332
+ "1957-08",
333
+ "1957-09",
334
+ "1957-10",
335
+ "1957-11",
336
+ "1957-12",
337
+ "1958-01",
338
+ "1958-02",
339
+ "1958-03",
340
+ "1958-04",
341
+ "1958-05",
342
+ "1958-06",
343
+ "1958-07",
344
+ "1958-08",
345
+ "1958-09",
346
+ "1958-10",
347
+ "1958-11",
348
+ "1958-12",
349
+ "1959-01",
350
+ "1959-02",
351
+ "1959-03",
352
+ "1959-04",
353
+ "1959-05",
354
+ "1959-06",
355
+ "1959-07",
356
+ "1959-08",
357
+ "1959-09",
358
+ "1959-10",
359
+ "1959-11",
360
+ "1959-12",
361
+ "1960-01",
362
+ "1960-02",
363
+ "1960-03",
364
+ "1960-04",
365
+ "1960-05",
366
+ "1960-06",
367
+ "1960-07",
368
+ "1960-08",
369
+ "1960-09",
370
+ "1960-10",
371
+ "1960-11",
372
+ "1960-12"
373
+ ],
374
+ "xaxis": "x",
375
+ "y": [
376
+ 112,
377
+ 118,
378
+ 132,
379
+ 129,
380
+ 121,
381
+ 135,
382
+ 148,
383
+ 148,
384
+ 136,
385
+ 119,
386
+ 104,
387
+ 118,
388
+ 115,
389
+ 126,
390
+ 141,
391
+ 135,
392
+ 125,
393
+ 149,
394
+ 170,
395
+ 170,
396
+ 158,
397
+ 133,
398
+ 114,
399
+ 140,
400
+ 145,
401
+ 150,
402
+ 178,
403
+ 163,
404
+ 172,
405
+ 178,
406
+ 199,
407
+ 199,
408
+ 184,
409
+ 162,
410
+ 146,
411
+ 166,
412
+ 171,
413
+ 180,
414
+ 193,
415
+ 181,
416
+ 183,
417
+ 218,
418
+ 230,
419
+ 242,
420
+ 209,
421
+ 191,
422
+ 172,
423
+ 194,
424
+ 196,
425
+ 196,
426
+ 236,
427
+ 235,
428
+ 229,
429
+ 243,
430
+ 264,
431
+ 272,
432
+ 237,
433
+ 211,
434
+ 180,
435
+ 201,
436
+ 204,
437
+ 188,
438
+ 235,
439
+ 227,
440
+ 234,
441
+ 264,
442
+ 302,
443
+ 293,
444
+ 259,
445
+ 229,
446
+ 203,
447
+ 229,
448
+ 242,
449
+ 233,
450
+ 267,
451
+ 269,
452
+ 270,
453
+ 315,
454
+ 364,
455
+ 347,
456
+ 312,
457
+ 274,
458
+ 237,
459
+ 278,
460
+ 284,
461
+ 277,
462
+ 317,
463
+ 313,
464
+ 318,
465
+ 374,
466
+ 413,
467
+ 405,
468
+ 355,
469
+ 306,
470
+ 271,
471
+ 306,
472
+ 315,
473
+ 301,
474
+ 356,
475
+ 348,
476
+ 355,
477
+ 422,
478
+ 465,
479
+ 467,
480
+ 404,
481
+ 347,
482
+ 305,
483
+ 336,
484
+ 340,
485
+ 318,
486
+ 362,
487
+ 348,
488
+ 363,
489
+ 435,
490
+ 491,
491
+ 505,
492
+ 404,
493
+ 359,
494
+ 310,
495
+ 337,
496
+ 360,
497
+ 342,
498
+ 406,
499
+ 396,
500
+ 420,
501
+ 472,
502
+ 548,
503
+ 559,
504
+ 463,
505
+ 407,
506
+ 362,
507
+ 405,
508
+ 417,
509
+ 391,
510
+ 419,
511
+ 461,
512
+ 472,
513
+ 535,
514
+ 622,
515
+ 606,
516
+ 508,
517
+ 461,
518
+ 390,
519
+ 432
520
+ ],
521
+ "yaxis": "y"
522
+ }
523
+ ],
524
+ "layout": {
525
+ "legend": {
526
+ "tracegroupgap": 0
527
+ },
528
+ "margin": {
529
+ "t": 60
530
+ },
531
+ "template": {
532
+ "data": {
533
+ "bar": [
534
+ {
535
+ "error_x": {
536
+ "color": "#2a3f5f"
537
+ },
538
+ "error_y": {
539
+ "color": "#2a3f5f"
540
+ },
541
+ "marker": {
542
+ "line": {
543
+ "color": "#E5ECF6",
544
+ "width": 0.5
545
+ },
546
+ "pattern": {
547
+ "fillmode": "overlay",
548
+ "size": 10,
549
+ "solidity": 0.2
550
+ }
551
+ },
552
+ "type": "bar"
553
+ }
554
+ ],
555
+ "barpolar": [
556
+ {
557
+ "marker": {
558
+ "line": {
559
+ "color": "#E5ECF6",
560
+ "width": 0.5
561
+ },
562
+ "pattern": {
563
+ "fillmode": "overlay",
564
+ "size": 10,
565
+ "solidity": 0.2
566
+ }
567
+ },
568
+ "type": "barpolar"
569
+ }
570
+ ],
571
+ "carpet": [
572
+ {
573
+ "aaxis": {
574
+ "endlinecolor": "#2a3f5f",
575
+ "gridcolor": "white",
576
+ "linecolor": "white",
577
+ "minorgridcolor": "white",
578
+ "startlinecolor": "#2a3f5f"
579
+ },
580
+ "baxis": {
581
+ "endlinecolor": "#2a3f5f",
582
+ "gridcolor": "white",
583
+ "linecolor": "white",
584
+ "minorgridcolor": "white",
585
+ "startlinecolor": "#2a3f5f"
586
+ },
587
+ "type": "carpet"
588
+ }
589
+ ],
590
+ "choropleth": [
591
+ {
592
+ "colorbar": {
593
+ "outlinewidth": 0,
594
+ "ticks": ""
595
+ },
596
+ "type": "choropleth"
597
+ }
598
+ ],
599
+ "contour": [
600
+ {
601
+ "colorbar": {
602
+ "outlinewidth": 0,
603
+ "ticks": ""
604
+ },
605
+ "colorscale": [
606
+ [
607
+ 0,
608
+ "#0d0887"
609
+ ],
610
+ [
611
+ 0.1111111111111111,
612
+ "#46039f"
613
+ ],
614
+ [
615
+ 0.2222222222222222,
616
+ "#7201a8"
617
+ ],
618
+ [
619
+ 0.3333333333333333,
620
+ "#9c179e"
621
+ ],
622
+ [
623
+ 0.4444444444444444,
624
+ "#bd3786"
625
+ ],
626
+ [
627
+ 0.5555555555555556,
628
+ "#d8576b"
629
+ ],
630
+ [
631
+ 0.6666666666666666,
632
+ "#ed7953"
633
+ ],
634
+ [
635
+ 0.7777777777777778,
636
+ "#fb9f3a"
637
+ ],
638
+ [
639
+ 0.8888888888888888,
640
+ "#fdca26"
641
+ ],
642
+ [
643
+ 1,
644
+ "#f0f921"
645
+ ]
646
+ ],
647
+ "type": "contour"
648
+ }
649
+ ],
650
+ "contourcarpet": [
651
+ {
652
+ "colorbar": {
653
+ "outlinewidth": 0,
654
+ "ticks": ""
655
+ },
656
+ "type": "contourcarpet"
657
+ }
658
+ ],
659
+ "heatmap": [
660
+ {
661
+ "colorbar": {
662
+ "outlinewidth": 0,
663
+ "ticks": ""
664
+ },
665
+ "colorscale": [
666
+ [
667
+ 0,
668
+ "#0d0887"
669
+ ],
670
+ [
671
+ 0.1111111111111111,
672
+ "#46039f"
673
+ ],
674
+ [
675
+ 0.2222222222222222,
676
+ "#7201a8"
677
+ ],
678
+ [
679
+ 0.3333333333333333,
680
+ "#9c179e"
681
+ ],
682
+ [
683
+ 0.4444444444444444,
684
+ "#bd3786"
685
+ ],
686
+ [
687
+ 0.5555555555555556,
688
+ "#d8576b"
689
+ ],
690
+ [
691
+ 0.6666666666666666,
692
+ "#ed7953"
693
+ ],
694
+ [
695
+ 0.7777777777777778,
696
+ "#fb9f3a"
697
+ ],
698
+ [
699
+ 0.8888888888888888,
700
+ "#fdca26"
701
+ ],
702
+ [
703
+ 1,
704
+ "#f0f921"
705
+ ]
706
+ ],
707
+ "type": "heatmap"
708
+ }
709
+ ],
710
+ "heatmapgl": [
711
+ {
712
+ "colorbar": {
713
+ "outlinewidth": 0,
714
+ "ticks": ""
715
+ },
716
+ "colorscale": [
717
+ [
718
+ 0,
719
+ "#0d0887"
720
+ ],
721
+ [
722
+ 0.1111111111111111,
723
+ "#46039f"
724
+ ],
725
+ [
726
+ 0.2222222222222222,
727
+ "#7201a8"
728
+ ],
729
+ [
730
+ 0.3333333333333333,
731
+ "#9c179e"
732
+ ],
733
+ [
734
+ 0.4444444444444444,
735
+ "#bd3786"
736
+ ],
737
+ [
738
+ 0.5555555555555556,
739
+ "#d8576b"
740
+ ],
741
+ [
742
+ 0.6666666666666666,
743
+ "#ed7953"
744
+ ],
745
+ [
746
+ 0.7777777777777778,
747
+ "#fb9f3a"
748
+ ],
749
+ [
750
+ 0.8888888888888888,
751
+ "#fdca26"
752
+ ],
753
+ [
754
+ 1,
755
+ "#f0f921"
756
+ ]
757
+ ],
758
+ "type": "heatmapgl"
759
+ }
760
+ ],
761
+ "histogram": [
762
+ {
763
+ "marker": {
764
+ "pattern": {
765
+ "fillmode": "overlay",
766
+ "size": 10,
767
+ "solidity": 0.2
768
+ }
769
+ },
770
+ "type": "histogram"
771
+ }
772
+ ],
773
+ "histogram2d": [
774
+ {
775
+ "colorbar": {
776
+ "outlinewidth": 0,
777
+ "ticks": ""
778
+ },
779
+ "colorscale": [
780
+ [
781
+ 0,
782
+ "#0d0887"
783
+ ],
784
+ [
785
+ 0.1111111111111111,
786
+ "#46039f"
787
+ ],
788
+ [
789
+ 0.2222222222222222,
790
+ "#7201a8"
791
+ ],
792
+ [
793
+ 0.3333333333333333,
794
+ "#9c179e"
795
+ ],
796
+ [
797
+ 0.4444444444444444,
798
+ "#bd3786"
799
+ ],
800
+ [
801
+ 0.5555555555555556,
802
+ "#d8576b"
803
+ ],
804
+ [
805
+ 0.6666666666666666,
806
+ "#ed7953"
807
+ ],
808
+ [
809
+ 0.7777777777777778,
810
+ "#fb9f3a"
811
+ ],
812
+ [
813
+ 0.8888888888888888,
814
+ "#fdca26"
815
+ ],
816
+ [
817
+ 1,
818
+ "#f0f921"
819
+ ]
820
+ ],
821
+ "type": "histogram2d"
822
+ }
823
+ ],
824
+ "histogram2dcontour": [
825
+ {
826
+ "colorbar": {
827
+ "outlinewidth": 0,
828
+ "ticks": ""
829
+ },
830
+ "colorscale": [
831
+ [
832
+ 0,
833
+ "#0d0887"
834
+ ],
835
+ [
836
+ 0.1111111111111111,
837
+ "#46039f"
838
+ ],
839
+ [
840
+ 0.2222222222222222,
841
+ "#7201a8"
842
+ ],
843
+ [
844
+ 0.3333333333333333,
845
+ "#9c179e"
846
+ ],
847
+ [
848
+ 0.4444444444444444,
849
+ "#bd3786"
850
+ ],
851
+ [
852
+ 0.5555555555555556,
853
+ "#d8576b"
854
+ ],
855
+ [
856
+ 0.6666666666666666,
857
+ "#ed7953"
858
+ ],
859
+ [
860
+ 0.7777777777777778,
861
+ "#fb9f3a"
862
+ ],
863
+ [
864
+ 0.8888888888888888,
865
+ "#fdca26"
866
+ ],
867
+ [
868
+ 1,
869
+ "#f0f921"
870
+ ]
871
+ ],
872
+ "type": "histogram2dcontour"
873
+ }
874
+ ],
875
+ "mesh3d": [
876
+ {
877
+ "colorbar": {
878
+ "outlinewidth": 0,
879
+ "ticks": ""
880
+ },
881
+ "type": "mesh3d"
882
+ }
883
+ ],
884
+ "parcoords": [
885
+ {
886
+ "line": {
887
+ "colorbar": {
888
+ "outlinewidth": 0,
889
+ "ticks": ""
890
+ }
891
+ },
892
+ "type": "parcoords"
893
+ }
894
+ ],
895
+ "pie": [
896
+ {
897
+ "automargin": true,
898
+ "type": "pie"
899
+ }
900
+ ],
901
+ "scatter": [
902
+ {
903
+ "fillpattern": {
904
+ "fillmode": "overlay",
905
+ "size": 10,
906
+ "solidity": 0.2
907
+ },
908
+ "type": "scatter"
909
+ }
910
+ ],
911
+ "scatter3d": [
912
+ {
913
+ "line": {
914
+ "colorbar": {
915
+ "outlinewidth": 0,
916
+ "ticks": ""
917
+ }
918
+ },
919
+ "marker": {
920
+ "colorbar": {
921
+ "outlinewidth": 0,
922
+ "ticks": ""
923
+ }
924
+ },
925
+ "type": "scatter3d"
926
+ }
927
+ ],
928
+ "scattercarpet": [
929
+ {
930
+ "marker": {
931
+ "colorbar": {
932
+ "outlinewidth": 0,
933
+ "ticks": ""
934
+ }
935
+ },
936
+ "type": "scattercarpet"
937
+ }
938
+ ],
939
+ "scattergeo": [
940
+ {
941
+ "marker": {
942
+ "colorbar": {
943
+ "outlinewidth": 0,
944
+ "ticks": ""
945
+ }
946
+ },
947
+ "type": "scattergeo"
948
+ }
949
+ ],
950
+ "scattergl": [
951
+ {
952
+ "marker": {
953
+ "colorbar": {
954
+ "outlinewidth": 0,
955
+ "ticks": ""
956
+ }
957
+ },
958
+ "type": "scattergl"
959
+ }
960
+ ],
961
+ "scattermapbox": [
962
+ {
963
+ "marker": {
964
+ "colorbar": {
965
+ "outlinewidth": 0,
966
+ "ticks": ""
967
+ }
968
+ },
969
+ "type": "scattermapbox"
970
+ }
971
+ ],
972
+ "scatterpolar": [
973
+ {
974
+ "marker": {
975
+ "colorbar": {
976
+ "outlinewidth": 0,
977
+ "ticks": ""
978
+ }
979
+ },
980
+ "type": "scatterpolar"
981
+ }
982
+ ],
983
+ "scatterpolargl": [
984
+ {
985
+ "marker": {
986
+ "colorbar": {
987
+ "outlinewidth": 0,
988
+ "ticks": ""
989
+ }
990
+ },
991
+ "type": "scatterpolargl"
992
+ }
993
+ ],
994
+ "scatterternary": [
995
+ {
996
+ "marker": {
997
+ "colorbar": {
998
+ "outlinewidth": 0,
999
+ "ticks": ""
1000
+ }
1001
+ },
1002
+ "type": "scatterternary"
1003
+ }
1004
+ ],
1005
+ "surface": [
1006
+ {
1007
+ "colorbar": {
1008
+ "outlinewidth": 0,
1009
+ "ticks": ""
1010
+ },
1011
+ "colorscale": [
1012
+ [
1013
+ 0,
1014
+ "#0d0887"
1015
+ ],
1016
+ [
1017
+ 0.1111111111111111,
1018
+ "#46039f"
1019
+ ],
1020
+ [
1021
+ 0.2222222222222222,
1022
+ "#7201a8"
1023
+ ],
1024
+ [
1025
+ 0.3333333333333333,
1026
+ "#9c179e"
1027
+ ],
1028
+ [
1029
+ 0.4444444444444444,
1030
+ "#bd3786"
1031
+ ],
1032
+ [
1033
+ 0.5555555555555556,
1034
+ "#d8576b"
1035
+ ],
1036
+ [
1037
+ 0.6666666666666666,
1038
+ "#ed7953"
1039
+ ],
1040
+ [
1041
+ 0.7777777777777778,
1042
+ "#fb9f3a"
1043
+ ],
1044
+ [
1045
+ 0.8888888888888888,
1046
+ "#fdca26"
1047
+ ],
1048
+ [
1049
+ 1,
1050
+ "#f0f921"
1051
+ ]
1052
+ ],
1053
+ "type": "surface"
1054
+ }
1055
+ ],
1056
+ "table": [
1057
+ {
1058
+ "cells": {
1059
+ "fill": {
1060
+ "color": "#EBF0F8"
1061
+ },
1062
+ "line": {
1063
+ "color": "white"
1064
+ }
1065
+ },
1066
+ "header": {
1067
+ "fill": {
1068
+ "color": "#C8D4E3"
1069
+ },
1070
+ "line": {
1071
+ "color": "white"
1072
+ }
1073
+ },
1074
+ "type": "table"
1075
+ }
1076
+ ]
1077
+ },
1078
+ "layout": {
1079
+ "annotationdefaults": {
1080
+ "arrowcolor": "#2a3f5f",
1081
+ "arrowhead": 0,
1082
+ "arrowwidth": 1
1083
+ },
1084
+ "autotypenumbers": "strict",
1085
+ "coloraxis": {
1086
+ "colorbar": {
1087
+ "outlinewidth": 0,
1088
+ "ticks": ""
1089
+ }
1090
+ },
1091
+ "colorscale": {
1092
+ "diverging": [
1093
+ [
1094
+ 0,
1095
+ "#8e0152"
1096
+ ],
1097
+ [
1098
+ 0.1,
1099
+ "#c51b7d"
1100
+ ],
1101
+ [
1102
+ 0.2,
1103
+ "#de77ae"
1104
+ ],
1105
+ [
1106
+ 0.3,
1107
+ "#f1b6da"
1108
+ ],
1109
+ [
1110
+ 0.4,
1111
+ "#fde0ef"
1112
+ ],
1113
+ [
1114
+ 0.5,
1115
+ "#f7f7f7"
1116
+ ],
1117
+ [
1118
+ 0.6,
1119
+ "#e6f5d0"
1120
+ ],
1121
+ [
1122
+ 0.7,
1123
+ "#b8e186"
1124
+ ],
1125
+ [
1126
+ 0.8,
1127
+ "#7fbc41"
1128
+ ],
1129
+ [
1130
+ 0.9,
1131
+ "#4d9221"
1132
+ ],
1133
+ [
1134
+ 1,
1135
+ "#276419"
1136
+ ]
1137
+ ],
1138
+ "sequential": [
1139
+ [
1140
+ 0,
1141
+ "#0d0887"
1142
+ ],
1143
+ [
1144
+ 0.1111111111111111,
1145
+ "#46039f"
1146
+ ],
1147
+ [
1148
+ 0.2222222222222222,
1149
+ "#7201a8"
1150
+ ],
1151
+ [
1152
+ 0.3333333333333333,
1153
+ "#9c179e"
1154
+ ],
1155
+ [
1156
+ 0.4444444444444444,
1157
+ "#bd3786"
1158
+ ],
1159
+ [
1160
+ 0.5555555555555556,
1161
+ "#d8576b"
1162
+ ],
1163
+ [
1164
+ 0.6666666666666666,
1165
+ "#ed7953"
1166
+ ],
1167
+ [
1168
+ 0.7777777777777778,
1169
+ "#fb9f3a"
1170
+ ],
1171
+ [
1172
+ 0.8888888888888888,
1173
+ "#fdca26"
1174
+ ],
1175
+ [
1176
+ 1,
1177
+ "#f0f921"
1178
+ ]
1179
+ ],
1180
+ "sequentialminus": [
1181
+ [
1182
+ 0,
1183
+ "#0d0887"
1184
+ ],
1185
+ [
1186
+ 0.1111111111111111,
1187
+ "#46039f"
1188
+ ],
1189
+ [
1190
+ 0.2222222222222222,
1191
+ "#7201a8"
1192
+ ],
1193
+ [
1194
+ 0.3333333333333333,
1195
+ "#9c179e"
1196
+ ],
1197
+ [
1198
+ 0.4444444444444444,
1199
+ "#bd3786"
1200
+ ],
1201
+ [
1202
+ 0.5555555555555556,
1203
+ "#d8576b"
1204
+ ],
1205
+ [
1206
+ 0.6666666666666666,
1207
+ "#ed7953"
1208
+ ],
1209
+ [
1210
+ 0.7777777777777778,
1211
+ "#fb9f3a"
1212
+ ],
1213
+ [
1214
+ 0.8888888888888888,
1215
+ "#fdca26"
1216
+ ],
1217
+ [
1218
+ 1,
1219
+ "#f0f921"
1220
+ ]
1221
+ ]
1222
+ },
1223
+ "colorway": [
1224
+ "#636efa",
1225
+ "#EF553B",
1226
+ "#00cc96",
1227
+ "#ab63fa",
1228
+ "#FFA15A",
1229
+ "#19d3f3",
1230
+ "#FF6692",
1231
+ "#B6E880",
1232
+ "#FF97FF",
1233
+ "#FECB52"
1234
+ ],
1235
+ "font": {
1236
+ "color": "#2a3f5f"
1237
+ },
1238
+ "geo": {
1239
+ "bgcolor": "white",
1240
+ "lakecolor": "white",
1241
+ "landcolor": "#E5ECF6",
1242
+ "showlakes": true,
1243
+ "showland": true,
1244
+ "subunitcolor": "white"
1245
+ },
1246
+ "hoverlabel": {
1247
+ "align": "left"
1248
+ },
1249
+ "hovermode": "closest",
1250
+ "mapbox": {
1251
+ "style": "light"
1252
+ },
1253
+ "paper_bgcolor": "white",
1254
+ "plot_bgcolor": "#E5ECF6",
1255
+ "polar": {
1256
+ "angularaxis": {
1257
+ "gridcolor": "white",
1258
+ "linecolor": "white",
1259
+ "ticks": ""
1260
+ },
1261
+ "bgcolor": "#E5ECF6",
1262
+ "radialaxis": {
1263
+ "gridcolor": "white",
1264
+ "linecolor": "white",
1265
+ "ticks": ""
1266
+ }
1267
+ },
1268
+ "scene": {
1269
+ "xaxis": {
1270
+ "backgroundcolor": "#E5ECF6",
1271
+ "gridcolor": "white",
1272
+ "gridwidth": 2,
1273
+ "linecolor": "white",
1274
+ "showbackground": true,
1275
+ "ticks": "",
1276
+ "zerolinecolor": "white"
1277
+ },
1278
+ "yaxis": {
1279
+ "backgroundcolor": "#E5ECF6",
1280
+ "gridcolor": "white",
1281
+ "gridwidth": 2,
1282
+ "linecolor": "white",
1283
+ "showbackground": true,
1284
+ "ticks": "",
1285
+ "zerolinecolor": "white"
1286
+ },
1287
+ "zaxis": {
1288
+ "backgroundcolor": "#E5ECF6",
1289
+ "gridcolor": "white",
1290
+ "gridwidth": 2,
1291
+ "linecolor": "white",
1292
+ "showbackground": true,
1293
+ "ticks": "",
1294
+ "zerolinecolor": "white"
1295
+ }
1296
+ },
1297
+ "shapedefaults": {
1298
+ "line": {
1299
+ "color": "#2a3f5f"
1300
+ }
1301
+ },
1302
+ "ternary": {
1303
+ "aaxis": {
1304
+ "gridcolor": "white",
1305
+ "linecolor": "white",
1306
+ "ticks": ""
1307
+ },
1308
+ "baxis": {
1309
+ "gridcolor": "white",
1310
+ "linecolor": "white",
1311
+ "ticks": ""
1312
+ },
1313
+ "bgcolor": "#E5ECF6",
1314
+ "caxis": {
1315
+ "gridcolor": "white",
1316
+ "linecolor": "white",
1317
+ "ticks": ""
1318
+ }
1319
+ },
1320
+ "title": {
1321
+ "x": 0.05
1322
+ },
1323
+ "xaxis": {
1324
+ "automargin": true,
1325
+ "gridcolor": "white",
1326
+ "linecolor": "white",
1327
+ "ticks": "",
1328
+ "title": {
1329
+ "standoff": 15
1330
+ },
1331
+ "zerolinecolor": "white",
1332
+ "zerolinewidth": 2
1333
+ },
1334
+ "yaxis": {
1335
+ "automargin": true,
1336
+ "gridcolor": "white",
1337
+ "linecolor": "white",
1338
+ "ticks": "",
1339
+ "title": {
1340
+ "standoff": 15
1341
+ },
1342
+ "zerolinecolor": "white",
1343
+ "zerolinewidth": 2
1344
+ }
1345
+ }
1346
+ },
1347
+ "xaxis": {
1348
+ "anchor": "y",
1349
+ "domain": [
1350
+ 0,
1351
+ 1
1352
+ ],
1353
+ "title": {
1354
+ "text": "Date"
1355
+ }
1356
+ },
1357
+ "yaxis": {
1358
+ "anchor": "x",
1359
+ "domain": [
1360
+ 0,
1361
+ 1
1362
+ ],
1363
+ "title": {
1364
+ "text": "Passengers"
1365
+ }
1366
+ }
1367
+ }
1368
+ }
1369
+ },
1370
+ "metadata": {},
1371
+ "output_type": "display_data"
1372
+ }
1373
+ ],
1374
+ "source": [
1375
+ "fig"
1376
+ ]
1377
+ },
1378
+ {
1379
+ "cell_type": "code",
1380
+ "execution_count": 7,
1381
+ "metadata": {},
1382
+ "outputs": [
1383
+ {
1384
+ "data": {
1385
+ "application/vnd.plotly.v1+json": {
1386
+ "config": {
1387
+ "plotlyServerURL": "https://plot.ly"
1388
+ },
1389
+ "data": [
1390
+ {
1391
+ "hovertemplate": "Date=%{x}<br>Passengers=%{y}<extra></extra>",
1392
+ "legendgroup": "",
1393
+ "line": {
1394
+ "color": "#636efa",
1395
+ "dash": "solid"
1396
+ },
1397
+ "marker": {
1398
+ "symbol": "circle"
1399
+ },
1400
+ "mode": "lines",
1401
+ "name": "",
1402
+ "orientation": "v",
1403
+ "showlegend": false,
1404
+ "type": "scatter",
1405
+ "x": [
1406
+ "1949-01",
1407
+ "1949-02",
1408
+ "1949-03",
1409
+ "1949-04",
1410
+ "1949-05",
1411
+ "1949-06",
1412
+ "1949-07",
1413
+ "1949-08",
1414
+ "1949-09",
1415
+ "1949-10",
1416
+ "1949-11",
1417
+ "1949-12",
1418
+ "1950-01",
1419
+ "1950-02",
1420
+ "1950-03",
1421
+ "1950-04",
1422
+ "1950-05",
1423
+ "1950-06",
1424
+ "1950-07",
1425
+ "1950-08",
1426
+ "1950-09",
1427
+ "1950-10",
1428
+ "1950-11",
1429
+ "1950-12",
1430
+ "1951-01",
1431
+ "1951-02",
1432
+ "1951-03",
1433
+ "1951-04",
1434
+ "1951-05",
1435
+ "1951-06",
1436
+ "1951-07",
1437
+ "1951-08",
1438
+ "1951-09",
1439
+ "1951-10",
1440
+ "1951-11",
1441
+ "1951-12",
1442
+ "1952-01",
1443
+ "1952-02",
1444
+ "1952-03",
1445
+ "1952-04",
1446
+ "1952-05",
1447
+ "1952-06",
1448
+ "1952-07",
1449
+ "1952-08",
1450
+ "1952-09",
1451
+ "1952-10",
1452
+ "1952-11",
1453
+ "1952-12",
1454
+ "1953-01",
1455
+ "1953-02",
1456
+ "1953-03",
1457
+ "1953-04",
1458
+ "1953-05",
1459
+ "1953-06",
1460
+ "1953-07",
1461
+ "1953-08",
1462
+ "1953-09",
1463
+ "1953-10",
1464
+ "1953-11",
1465
+ "1953-12",
1466
+ "1954-01",
1467
+ "1954-02",
1468
+ "1954-03",
1469
+ "1954-04",
1470
+ "1954-05",
1471
+ "1954-06",
1472
+ "1954-07",
1473
+ "1954-08",
1474
+ "1954-09",
1475
+ "1954-10",
1476
+ "1954-11",
1477
+ "1954-12",
1478
+ "1955-01",
1479
+ "1955-02",
1480
+ "1955-03",
1481
+ "1955-04",
1482
+ "1955-05",
1483
+ "1955-06",
1484
+ "1955-07",
1485
+ "1955-08",
1486
+ "1955-09",
1487
+ "1955-10",
1488
+ "1955-11",
1489
+ "1955-12",
1490
+ "1956-01",
1491
+ "1956-02",
1492
+ "1956-03",
1493
+ "1956-04",
1494
+ "1956-05",
1495
+ "1956-06",
1496
+ "1956-07",
1497
+ "1956-08",
1498
+ "1956-09",
1499
+ "1956-10",
1500
+ "1956-11",
1501
+ "1956-12",
1502
+ "1957-01",
1503
+ "1957-02",
1504
+ "1957-03",
1505
+ "1957-04",
1506
+ "1957-05",
1507
+ "1957-06",
1508
+ "1957-07",
1509
+ "1957-08",
1510
+ "1957-09",
1511
+ "1957-10",
1512
+ "1957-11",
1513
+ "1957-12",
1514
+ "1958-01",
1515
+ "1958-02",
1516
+ "1958-03",
1517
+ "1958-04",
1518
+ "1958-05",
1519
+ "1958-06",
1520
+ "1958-07",
1521
+ "1958-08",
1522
+ "1958-09",
1523
+ "1958-10",
1524
+ "1958-11",
1525
+ "1958-12",
1526
+ "1959-01",
1527
+ "1959-02",
1528
+ "1959-03",
1529
+ "1959-04",
1530
+ "1959-05",
1531
+ "1959-06",
1532
+ "1959-07",
1533
+ "1959-08",
1534
+ "1959-09",
1535
+ "1959-10",
1536
+ "1959-11",
1537
+ "1959-12",
1538
+ "1960-01",
1539
+ "1960-02",
1540
+ "1960-03",
1541
+ "1960-04",
1542
+ "1960-05",
1543
+ "1960-06",
1544
+ "1960-07",
1545
+ "1960-08",
1546
+ "1960-09",
1547
+ "1960-10",
1548
+ "1960-11",
1549
+ "1960-12"
1550
+ ],
1551
+ "xaxis": "x",
1552
+ "y": [
1553
+ 112,
1554
+ 118,
1555
+ 132,
1556
+ 129,
1557
+ 121,
1558
+ 135,
1559
+ 148,
1560
+ 148,
1561
+ 136,
1562
+ 119,
1563
+ 104,
1564
+ 118,
1565
+ 115,
1566
+ 126,
1567
+ 141,
1568
+ 135,
1569
+ 125,
1570
+ 149,
1571
+ 170,
1572
+ 170,
1573
+ 158,
1574
+ 133,
1575
+ 114,
1576
+ 140,
1577
+ 145,
1578
+ 150,
1579
+ 178,
1580
+ 163,
1581
+ 172,
1582
+ 178,
1583
+ 199,
1584
+ 199,
1585
+ 184,
1586
+ 162,
1587
+ 146,
1588
+ 166,
1589
+ 171,
1590
+ 180,
1591
+ 193,
1592
+ 181,
1593
+ 183,
1594
+ 218,
1595
+ 230,
1596
+ 242,
1597
+ 209,
1598
+ 191,
1599
+ 172,
1600
+ 194,
1601
+ 196,
1602
+ 196,
1603
+ 236,
1604
+ 235,
1605
+ 229,
1606
+ 243,
1607
+ 264,
1608
+ 272,
1609
+ 237,
1610
+ 211,
1611
+ 180,
1612
+ 201,
1613
+ 204,
1614
+ 188,
1615
+ 235,
1616
+ 227,
1617
+ 234,
1618
+ 264,
1619
+ 302,
1620
+ 293,
1621
+ 259,
1622
+ 229,
1623
+ 203,
1624
+ 229,
1625
+ 242,
1626
+ 233,
1627
+ 267,
1628
+ 269,
1629
+ 270,
1630
+ 315,
1631
+ 364,
1632
+ 347,
1633
+ 312,
1634
+ 274,
1635
+ 237,
1636
+ 278,
1637
+ 284,
1638
+ 277,
1639
+ 317,
1640
+ 313,
1641
+ 318,
1642
+ 374,
1643
+ 413,
1644
+ 405,
1645
+ 355,
1646
+ 306,
1647
+ 271,
1648
+ 306,
1649
+ 315,
1650
+ 301,
1651
+ 356,
1652
+ 348,
1653
+ 355,
1654
+ 422,
1655
+ 465,
1656
+ 467,
1657
+ 404,
1658
+ 347,
1659
+ 305,
1660
+ 336,
1661
+ 340,
1662
+ 318,
1663
+ 362,
1664
+ 348,
1665
+ 363,
1666
+ 435,
1667
+ 491,
1668
+ 505,
1669
+ 404,
1670
+ 359,
1671
+ 310,
1672
+ 337,
1673
+ 360,
1674
+ 342,
1675
+ 406,
1676
+ 396,
1677
+ 420,
1678
+ 472,
1679
+ 548,
1680
+ 559,
1681
+ 463,
1682
+ 407,
1683
+ 362,
1684
+ 405,
1685
+ 417,
1686
+ 391,
1687
+ 419,
1688
+ 461,
1689
+ 472,
1690
+ 535,
1691
+ 622,
1692
+ 606,
1693
+ 508,
1694
+ 461,
1695
+ 390,
1696
+ 432
1697
+ ],
1698
+ "yaxis": "y"
1699
+ }
1700
+ ],
1701
+ "layout": {
1702
+ "font": {
1703
+ "size": 18
1704
+ },
1705
+ "height": 400,
1706
+ "legend": {
1707
+ "tracegroupgap": 0
1708
+ },
1709
+ "margin": {
1710
+ "t": 60
1711
+ },
1712
+ "template": {
1713
+ "data": {
1714
+ "bar": [
1715
+ {
1716
+ "error_x": {
1717
+ "color": "rgb(36,36,36)"
1718
+ },
1719
+ "error_y": {
1720
+ "color": "rgb(36,36,36)"
1721
+ },
1722
+ "marker": {
1723
+ "line": {
1724
+ "color": "white",
1725
+ "width": 0.5
1726
+ },
1727
+ "pattern": {
1728
+ "fillmode": "overlay",
1729
+ "size": 10,
1730
+ "solidity": 0.2
1731
+ }
1732
+ },
1733
+ "type": "bar"
1734
+ }
1735
+ ],
1736
+ "barpolar": [
1737
+ {
1738
+ "marker": {
1739
+ "line": {
1740
+ "color": "white",
1741
+ "width": 0.5
1742
+ },
1743
+ "pattern": {
1744
+ "fillmode": "overlay",
1745
+ "size": 10,
1746
+ "solidity": 0.2
1747
+ }
1748
+ },
1749
+ "type": "barpolar"
1750
+ }
1751
+ ],
1752
+ "carpet": [
1753
+ {
1754
+ "aaxis": {
1755
+ "endlinecolor": "rgb(36,36,36)",
1756
+ "gridcolor": "white",
1757
+ "linecolor": "white",
1758
+ "minorgridcolor": "white",
1759
+ "startlinecolor": "rgb(36,36,36)"
1760
+ },
1761
+ "baxis": {
1762
+ "endlinecolor": "rgb(36,36,36)",
1763
+ "gridcolor": "white",
1764
+ "linecolor": "white",
1765
+ "minorgridcolor": "white",
1766
+ "startlinecolor": "rgb(36,36,36)"
1767
+ },
1768
+ "type": "carpet"
1769
+ }
1770
+ ],
1771
+ "choropleth": [
1772
+ {
1773
+ "colorbar": {
1774
+ "outlinewidth": 1,
1775
+ "tickcolor": "rgb(36,36,36)",
1776
+ "ticks": "outside"
1777
+ },
1778
+ "type": "choropleth"
1779
+ }
1780
+ ],
1781
+ "contour": [
1782
+ {
1783
+ "colorbar": {
1784
+ "outlinewidth": 1,
1785
+ "tickcolor": "rgb(36,36,36)",
1786
+ "ticks": "outside"
1787
+ },
1788
+ "colorscale": [
1789
+ [
1790
+ 0,
1791
+ "#440154"
1792
+ ],
1793
+ [
1794
+ 0.1111111111111111,
1795
+ "#482878"
1796
+ ],
1797
+ [
1798
+ 0.2222222222222222,
1799
+ "#3e4989"
1800
+ ],
1801
+ [
1802
+ 0.3333333333333333,
1803
+ "#31688e"
1804
+ ],
1805
+ [
1806
+ 0.4444444444444444,
1807
+ "#26828e"
1808
+ ],
1809
+ [
1810
+ 0.5555555555555556,
1811
+ "#1f9e89"
1812
+ ],
1813
+ [
1814
+ 0.6666666666666666,
1815
+ "#35b779"
1816
+ ],
1817
+ [
1818
+ 0.7777777777777778,
1819
+ "#6ece58"
1820
+ ],
1821
+ [
1822
+ 0.8888888888888888,
1823
+ "#b5de2b"
1824
+ ],
1825
+ [
1826
+ 1,
1827
+ "#fde725"
1828
+ ]
1829
+ ],
1830
+ "type": "contour"
1831
+ }
1832
+ ],
1833
+ "contourcarpet": [
1834
+ {
1835
+ "colorbar": {
1836
+ "outlinewidth": 1,
1837
+ "tickcolor": "rgb(36,36,36)",
1838
+ "ticks": "outside"
1839
+ },
1840
+ "type": "contourcarpet"
1841
+ }
1842
+ ],
1843
+ "heatmap": [
1844
+ {
1845
+ "colorbar": {
1846
+ "outlinewidth": 1,
1847
+ "tickcolor": "rgb(36,36,36)",
1848
+ "ticks": "outside"
1849
+ },
1850
+ "colorscale": [
1851
+ [
1852
+ 0,
1853
+ "#440154"
1854
+ ],
1855
+ [
1856
+ 0.1111111111111111,
1857
+ "#482878"
1858
+ ],
1859
+ [
1860
+ 0.2222222222222222,
1861
+ "#3e4989"
1862
+ ],
1863
+ [
1864
+ 0.3333333333333333,
1865
+ "#31688e"
1866
+ ],
1867
+ [
1868
+ 0.4444444444444444,
1869
+ "#26828e"
1870
+ ],
1871
+ [
1872
+ 0.5555555555555556,
1873
+ "#1f9e89"
1874
+ ],
1875
+ [
1876
+ 0.6666666666666666,
1877
+ "#35b779"
1878
+ ],
1879
+ [
1880
+ 0.7777777777777778,
1881
+ "#6ece58"
1882
+ ],
1883
+ [
1884
+ 0.8888888888888888,
1885
+ "#b5de2b"
1886
+ ],
1887
+ [
1888
+ 1,
1889
+ "#fde725"
1890
+ ]
1891
+ ],
1892
+ "type": "heatmap"
1893
+ }
1894
+ ],
1895
+ "heatmapgl": [
1896
+ {
1897
+ "colorbar": {
1898
+ "outlinewidth": 1,
1899
+ "tickcolor": "rgb(36,36,36)",
1900
+ "ticks": "outside"
1901
+ },
1902
+ "colorscale": [
1903
+ [
1904
+ 0,
1905
+ "#440154"
1906
+ ],
1907
+ [
1908
+ 0.1111111111111111,
1909
+ "#482878"
1910
+ ],
1911
+ [
1912
+ 0.2222222222222222,
1913
+ "#3e4989"
1914
+ ],
1915
+ [
1916
+ 0.3333333333333333,
1917
+ "#31688e"
1918
+ ],
1919
+ [
1920
+ 0.4444444444444444,
1921
+ "#26828e"
1922
+ ],
1923
+ [
1924
+ 0.5555555555555556,
1925
+ "#1f9e89"
1926
+ ],
1927
+ [
1928
+ 0.6666666666666666,
1929
+ "#35b779"
1930
+ ],
1931
+ [
1932
+ 0.7777777777777778,
1933
+ "#6ece58"
1934
+ ],
1935
+ [
1936
+ 0.8888888888888888,
1937
+ "#b5de2b"
1938
+ ],
1939
+ [
1940
+ 1,
1941
+ "#fde725"
1942
+ ]
1943
+ ],
1944
+ "type": "heatmapgl"
1945
+ }
1946
+ ],
1947
+ "histogram": [
1948
+ {
1949
+ "marker": {
1950
+ "line": {
1951
+ "color": "white",
1952
+ "width": 0.6
1953
+ }
1954
+ },
1955
+ "type": "histogram"
1956
+ }
1957
+ ],
1958
+ "histogram2d": [
1959
+ {
1960
+ "colorbar": {
1961
+ "outlinewidth": 1,
1962
+ "tickcolor": "rgb(36,36,36)",
1963
+ "ticks": "outside"
1964
+ },
1965
+ "colorscale": [
1966
+ [
1967
+ 0,
1968
+ "#440154"
1969
+ ],
1970
+ [
1971
+ 0.1111111111111111,
1972
+ "#482878"
1973
+ ],
1974
+ [
1975
+ 0.2222222222222222,
1976
+ "#3e4989"
1977
+ ],
1978
+ [
1979
+ 0.3333333333333333,
1980
+ "#31688e"
1981
+ ],
1982
+ [
1983
+ 0.4444444444444444,
1984
+ "#26828e"
1985
+ ],
1986
+ [
1987
+ 0.5555555555555556,
1988
+ "#1f9e89"
1989
+ ],
1990
+ [
1991
+ 0.6666666666666666,
1992
+ "#35b779"
1993
+ ],
1994
+ [
1995
+ 0.7777777777777778,
1996
+ "#6ece58"
1997
+ ],
1998
+ [
1999
+ 0.8888888888888888,
2000
+ "#b5de2b"
2001
+ ],
2002
+ [
2003
+ 1,
2004
+ "#fde725"
2005
+ ]
2006
+ ],
2007
+ "type": "histogram2d"
2008
+ }
2009
+ ],
2010
+ "histogram2dcontour": [
2011
+ {
2012
+ "colorbar": {
2013
+ "outlinewidth": 1,
2014
+ "tickcolor": "rgb(36,36,36)",
2015
+ "ticks": "outside"
2016
+ },
2017
+ "colorscale": [
2018
+ [
2019
+ 0,
2020
+ "#440154"
2021
+ ],
2022
+ [
2023
+ 0.1111111111111111,
2024
+ "#482878"
2025
+ ],
2026
+ [
2027
+ 0.2222222222222222,
2028
+ "#3e4989"
2029
+ ],
2030
+ [
2031
+ 0.3333333333333333,
2032
+ "#31688e"
2033
+ ],
2034
+ [
2035
+ 0.4444444444444444,
2036
+ "#26828e"
2037
+ ],
2038
+ [
2039
+ 0.5555555555555556,
2040
+ "#1f9e89"
2041
+ ],
2042
+ [
2043
+ 0.6666666666666666,
2044
+ "#35b779"
2045
+ ],
2046
+ [
2047
+ 0.7777777777777778,
2048
+ "#6ece58"
2049
+ ],
2050
+ [
2051
+ 0.8888888888888888,
2052
+ "#b5de2b"
2053
+ ],
2054
+ [
2055
+ 1,
2056
+ "#fde725"
2057
+ ]
2058
+ ],
2059
+ "type": "histogram2dcontour"
2060
+ }
2061
+ ],
2062
+ "mesh3d": [
2063
+ {
2064
+ "colorbar": {
2065
+ "outlinewidth": 1,
2066
+ "tickcolor": "rgb(36,36,36)",
2067
+ "ticks": "outside"
2068
+ },
2069
+ "type": "mesh3d"
2070
+ }
2071
+ ],
2072
+ "parcoords": [
2073
+ {
2074
+ "line": {
2075
+ "colorbar": {
2076
+ "outlinewidth": 1,
2077
+ "tickcolor": "rgb(36,36,36)",
2078
+ "ticks": "outside"
2079
+ }
2080
+ },
2081
+ "type": "parcoords"
2082
+ }
2083
+ ],
2084
+ "pie": [
2085
+ {
2086
+ "automargin": true,
2087
+ "type": "pie"
2088
+ }
2089
+ ],
2090
+ "scatter": [
2091
+ {
2092
+ "fillpattern": {
2093
+ "fillmode": "overlay",
2094
+ "size": 10,
2095
+ "solidity": 0.2
2096
+ },
2097
+ "type": "scatter"
2098
+ }
2099
+ ],
2100
+ "scatter3d": [
2101
+ {
2102
+ "line": {
2103
+ "colorbar": {
2104
+ "outlinewidth": 1,
2105
+ "tickcolor": "rgb(36,36,36)",
2106
+ "ticks": "outside"
2107
+ }
2108
+ },
2109
+ "marker": {
2110
+ "colorbar": {
2111
+ "outlinewidth": 1,
2112
+ "tickcolor": "rgb(36,36,36)",
2113
+ "ticks": "outside"
2114
+ }
2115
+ },
2116
+ "type": "scatter3d"
2117
+ }
2118
+ ],
2119
+ "scattercarpet": [
2120
+ {
2121
+ "marker": {
2122
+ "colorbar": {
2123
+ "outlinewidth": 1,
2124
+ "tickcolor": "rgb(36,36,36)",
2125
+ "ticks": "outside"
2126
+ }
2127
+ },
2128
+ "type": "scattercarpet"
2129
+ }
2130
+ ],
2131
+ "scattergeo": [
2132
+ {
2133
+ "marker": {
2134
+ "colorbar": {
2135
+ "outlinewidth": 1,
2136
+ "tickcolor": "rgb(36,36,36)",
2137
+ "ticks": "outside"
2138
+ }
2139
+ },
2140
+ "type": "scattergeo"
2141
+ }
2142
+ ],
2143
+ "scattergl": [
2144
+ {
2145
+ "marker": {
2146
+ "colorbar": {
2147
+ "outlinewidth": 1,
2148
+ "tickcolor": "rgb(36,36,36)",
2149
+ "ticks": "outside"
2150
+ }
2151
+ },
2152
+ "type": "scattergl"
2153
+ }
2154
+ ],
2155
+ "scattermapbox": [
2156
+ {
2157
+ "marker": {
2158
+ "colorbar": {
2159
+ "outlinewidth": 1,
2160
+ "tickcolor": "rgb(36,36,36)",
2161
+ "ticks": "outside"
2162
+ }
2163
+ },
2164
+ "type": "scattermapbox"
2165
+ }
2166
+ ],
2167
+ "scatterpolar": [
2168
+ {
2169
+ "marker": {
2170
+ "colorbar": {
2171
+ "outlinewidth": 1,
2172
+ "tickcolor": "rgb(36,36,36)",
2173
+ "ticks": "outside"
2174
+ }
2175
+ },
2176
+ "type": "scatterpolar"
2177
+ }
2178
+ ],
2179
+ "scatterpolargl": [
2180
+ {
2181
+ "marker": {
2182
+ "colorbar": {
2183
+ "outlinewidth": 1,
2184
+ "tickcolor": "rgb(36,36,36)",
2185
+ "ticks": "outside"
2186
+ }
2187
+ },
2188
+ "type": "scatterpolargl"
2189
+ }
2190
+ ],
2191
+ "scatterternary": [
2192
+ {
2193
+ "marker": {
2194
+ "colorbar": {
2195
+ "outlinewidth": 1,
2196
+ "tickcolor": "rgb(36,36,36)",
2197
+ "ticks": "outside"
2198
+ }
2199
+ },
2200
+ "type": "scatterternary"
2201
+ }
2202
+ ],
2203
+ "surface": [
2204
+ {
2205
+ "colorbar": {
2206
+ "outlinewidth": 1,
2207
+ "tickcolor": "rgb(36,36,36)",
2208
+ "ticks": "outside"
2209
+ },
2210
+ "colorscale": [
2211
+ [
2212
+ 0,
2213
+ "#440154"
2214
+ ],
2215
+ [
2216
+ 0.1111111111111111,
2217
+ "#482878"
2218
+ ],
2219
+ [
2220
+ 0.2222222222222222,
2221
+ "#3e4989"
2222
+ ],
2223
+ [
2224
+ 0.3333333333333333,
2225
+ "#31688e"
2226
+ ],
2227
+ [
2228
+ 0.4444444444444444,
2229
+ "#26828e"
2230
+ ],
2231
+ [
2232
+ 0.5555555555555556,
2233
+ "#1f9e89"
2234
+ ],
2235
+ [
2236
+ 0.6666666666666666,
2237
+ "#35b779"
2238
+ ],
2239
+ [
2240
+ 0.7777777777777778,
2241
+ "#6ece58"
2242
+ ],
2243
+ [
2244
+ 0.8888888888888888,
2245
+ "#b5de2b"
2246
+ ],
2247
+ [
2248
+ 1,
2249
+ "#fde725"
2250
+ ]
2251
+ ],
2252
+ "type": "surface"
2253
+ }
2254
+ ],
2255
+ "table": [
2256
+ {
2257
+ "cells": {
2258
+ "fill": {
2259
+ "color": "rgb(237,237,237)"
2260
+ },
2261
+ "line": {
2262
+ "color": "white"
2263
+ }
2264
+ },
2265
+ "header": {
2266
+ "fill": {
2267
+ "color": "rgb(217,217,217)"
2268
+ },
2269
+ "line": {
2270
+ "color": "white"
2271
+ }
2272
+ },
2273
+ "type": "table"
2274
+ }
2275
+ ]
2276
+ },
2277
+ "layout": {
2278
+ "annotationdefaults": {
2279
+ "arrowhead": 0,
2280
+ "arrowwidth": 1
2281
+ },
2282
+ "autotypenumbers": "strict",
2283
+ "coloraxis": {
2284
+ "colorbar": {
2285
+ "outlinewidth": 1,
2286
+ "tickcolor": "rgb(36,36,36)",
2287
+ "ticks": "outside"
2288
+ }
2289
+ },
2290
+ "colorscale": {
2291
+ "diverging": [
2292
+ [
2293
+ 0,
2294
+ "rgb(103,0,31)"
2295
+ ],
2296
+ [
2297
+ 0.1,
2298
+ "rgb(178,24,43)"
2299
+ ],
2300
+ [
2301
+ 0.2,
2302
+ "rgb(214,96,77)"
2303
+ ],
2304
+ [
2305
+ 0.3,
2306
+ "rgb(244,165,130)"
2307
+ ],
2308
+ [
2309
+ 0.4,
2310
+ "rgb(253,219,199)"
2311
+ ],
2312
+ [
2313
+ 0.5,
2314
+ "rgb(247,247,247)"
2315
+ ],
2316
+ [
2317
+ 0.6,
2318
+ "rgb(209,229,240)"
2319
+ ],
2320
+ [
2321
+ 0.7,
2322
+ "rgb(146,197,222)"
2323
+ ],
2324
+ [
2325
+ 0.8,
2326
+ "rgb(67,147,195)"
2327
+ ],
2328
+ [
2329
+ 0.9,
2330
+ "rgb(33,102,172)"
2331
+ ],
2332
+ [
2333
+ 1,
2334
+ "rgb(5,48,97)"
2335
+ ]
2336
+ ],
2337
+ "sequential": [
2338
+ [
2339
+ 0,
2340
+ "#440154"
2341
+ ],
2342
+ [
2343
+ 0.1111111111111111,
2344
+ "#482878"
2345
+ ],
2346
+ [
2347
+ 0.2222222222222222,
2348
+ "#3e4989"
2349
+ ],
2350
+ [
2351
+ 0.3333333333333333,
2352
+ "#31688e"
2353
+ ],
2354
+ [
2355
+ 0.4444444444444444,
2356
+ "#26828e"
2357
+ ],
2358
+ [
2359
+ 0.5555555555555556,
2360
+ "#1f9e89"
2361
+ ],
2362
+ [
2363
+ 0.6666666666666666,
2364
+ "#35b779"
2365
+ ],
2366
+ [
2367
+ 0.7777777777777778,
2368
+ "#6ece58"
2369
+ ],
2370
+ [
2371
+ 0.8888888888888888,
2372
+ "#b5de2b"
2373
+ ],
2374
+ [
2375
+ 1,
2376
+ "#fde725"
2377
+ ]
2378
+ ],
2379
+ "sequentialminus": [
2380
+ [
2381
+ 0,
2382
+ "#440154"
2383
+ ],
2384
+ [
2385
+ 0.1111111111111111,
2386
+ "#482878"
2387
+ ],
2388
+ [
2389
+ 0.2222222222222222,
2390
+ "#3e4989"
2391
+ ],
2392
+ [
2393
+ 0.3333333333333333,
2394
+ "#31688e"
2395
+ ],
2396
+ [
2397
+ 0.4444444444444444,
2398
+ "#26828e"
2399
+ ],
2400
+ [
2401
+ 0.5555555555555556,
2402
+ "#1f9e89"
2403
+ ],
2404
+ [
2405
+ 0.6666666666666666,
2406
+ "#35b779"
2407
+ ],
2408
+ [
2409
+ 0.7777777777777778,
2410
+ "#6ece58"
2411
+ ],
2412
+ [
2413
+ 0.8888888888888888,
2414
+ "#b5de2b"
2415
+ ],
2416
+ [
2417
+ 1,
2418
+ "#fde725"
2419
+ ]
2420
+ ]
2421
+ },
2422
+ "colorway": [
2423
+ "#1F77B4",
2424
+ "#FF7F0E",
2425
+ "#2CA02C",
2426
+ "#D62728",
2427
+ "#9467BD",
2428
+ "#8C564B",
2429
+ "#E377C2",
2430
+ "#7F7F7F",
2431
+ "#BCBD22",
2432
+ "#17BECF"
2433
+ ],
2434
+ "font": {
2435
+ "color": "rgb(36,36,36)"
2436
+ },
2437
+ "geo": {
2438
+ "bgcolor": "white",
2439
+ "lakecolor": "white",
2440
+ "landcolor": "white",
2441
+ "showlakes": true,
2442
+ "showland": true,
2443
+ "subunitcolor": "white"
2444
+ },
2445
+ "hoverlabel": {
2446
+ "align": "left"
2447
+ },
2448
+ "hovermode": "closest",
2449
+ "mapbox": {
2450
+ "style": "light"
2451
+ },
2452
+ "paper_bgcolor": "white",
2453
+ "plot_bgcolor": "white",
2454
+ "polar": {
2455
+ "angularaxis": {
2456
+ "gridcolor": "rgb(232,232,232)",
2457
+ "linecolor": "rgb(36,36,36)",
2458
+ "showgrid": false,
2459
+ "showline": true,
2460
+ "ticks": "outside"
2461
+ },
2462
+ "bgcolor": "white",
2463
+ "radialaxis": {
2464
+ "gridcolor": "rgb(232,232,232)",
2465
+ "linecolor": "rgb(36,36,36)",
2466
+ "showgrid": false,
2467
+ "showline": true,
2468
+ "ticks": "outside"
2469
+ }
2470
+ },
2471
+ "scene": {
2472
+ "xaxis": {
2473
+ "backgroundcolor": "white",
2474
+ "gridcolor": "rgb(232,232,232)",
2475
+ "gridwidth": 2,
2476
+ "linecolor": "rgb(36,36,36)",
2477
+ "showbackground": true,
2478
+ "showgrid": false,
2479
+ "showline": true,
2480
+ "ticks": "outside",
2481
+ "zeroline": false,
2482
+ "zerolinecolor": "rgb(36,36,36)"
2483
+ },
2484
+ "yaxis": {
2485
+ "backgroundcolor": "white",
2486
+ "gridcolor": "rgb(232,232,232)",
2487
+ "gridwidth": 2,
2488
+ "linecolor": "rgb(36,36,36)",
2489
+ "showbackground": true,
2490
+ "showgrid": false,
2491
+ "showline": true,
2492
+ "ticks": "outside",
2493
+ "zeroline": false,
2494
+ "zerolinecolor": "rgb(36,36,36)"
2495
+ },
2496
+ "zaxis": {
2497
+ "backgroundcolor": "white",
2498
+ "gridcolor": "rgb(232,232,232)",
2499
+ "gridwidth": 2,
2500
+ "linecolor": "rgb(36,36,36)",
2501
+ "showbackground": true,
2502
+ "showgrid": false,
2503
+ "showline": true,
2504
+ "ticks": "outside",
2505
+ "zeroline": false,
2506
+ "zerolinecolor": "rgb(36,36,36)"
2507
+ }
2508
+ },
2509
+ "shapedefaults": {
2510
+ "fillcolor": "black",
2511
+ "line": {
2512
+ "width": 0
2513
+ },
2514
+ "opacity": 0.3
2515
+ },
2516
+ "ternary": {
2517
+ "aaxis": {
2518
+ "gridcolor": "rgb(232,232,232)",
2519
+ "linecolor": "rgb(36,36,36)",
2520
+ "showgrid": false,
2521
+ "showline": true,
2522
+ "ticks": "outside"
2523
+ },
2524
+ "baxis": {
2525
+ "gridcolor": "rgb(232,232,232)",
2526
+ "linecolor": "rgb(36,36,36)",
2527
+ "showgrid": false,
2528
+ "showline": true,
2529
+ "ticks": "outside"
2530
+ },
2531
+ "bgcolor": "white",
2532
+ "caxis": {
2533
+ "gridcolor": "rgb(232,232,232)",
2534
+ "linecolor": "rgb(36,36,36)",
2535
+ "showgrid": false,
2536
+ "showline": true,
2537
+ "ticks": "outside"
2538
+ }
2539
+ },
2540
+ "title": {
2541
+ "x": 0.05
2542
+ },
2543
+ "xaxis": {
2544
+ "automargin": true,
2545
+ "gridcolor": "rgb(232,232,232)",
2546
+ "linecolor": "rgb(36,36,36)",
2547
+ "showgrid": false,
2548
+ "showline": true,
2549
+ "ticks": "outside",
2550
+ "title": {
2551
+ "standoff": 15
2552
+ },
2553
+ "zeroline": false,
2554
+ "zerolinecolor": "rgb(36,36,36)"
2555
+ },
2556
+ "yaxis": {
2557
+ "automargin": true,
2558
+ "gridcolor": "rgb(232,232,232)",
2559
+ "linecolor": "rgb(36,36,36)",
2560
+ "showgrid": false,
2561
+ "showline": true,
2562
+ "ticks": "outside",
2563
+ "title": {
2564
+ "standoff": 15
2565
+ },
2566
+ "zeroline": false,
2567
+ "zerolinecolor": "rgb(36,36,36)"
2568
+ }
2569
+ }
2570
+ },
2571
+ "title": {
2572
+ "text": "Airline Passengers",
2573
+ "x": 0.5
2574
+ },
2575
+ "width": 650,
2576
+ "xaxis": {
2577
+ "anchor": "y",
2578
+ "domain": [
2579
+ 0,
2580
+ 1
2581
+ ],
2582
+ "title": {
2583
+ "text": "Date"
2584
+ }
2585
+ },
2586
+ "yaxis": {
2587
+ "anchor": "x",
2588
+ "domain": [
2589
+ 0,
2590
+ 1
2591
+ ],
2592
+ "title": {
2593
+ "text": "Passengers"
2594
+ }
2595
+ }
2596
+ }
2597
+ }
2598
+ },
2599
+ "metadata": {},
2600
+ "output_type": "display_data"
2601
+ }
2602
+ ],
2603
+ "source": [
2604
+ "fig.update_layout(\n",
2605
+ " template=\"simple_white\",\n",
2606
+ " font=dict(size=18),\n",
2607
+ " title_text=title,\n",
2608
+ " width=650,\n",
2609
+ " title_x=0.5,\n",
2610
+ " height=400,\n",
2611
+ ")\n",
2612
+ "\n",
2613
+ "if text:\n",
2614
+ " fig.add_annotation(\n",
2615
+ " x=\"1952-12-20\",\n",
2616
+ " y=10,\n",
2617
+ " text=f\"Lambda = {lam:.3f}\",\n",
2618
+ " align=\"left\",\n",
2619
+ " yanchor=\"bottom\",\n",
2620
+ " showarrow=False,\n",
2621
+ " font=dict(size=20, color=\"black\", family=\"Courier New, monospace\"),\n",
2622
+ " bordercolor=\"black\",\n",
2623
+ " borderwidth=2,\n",
2624
+ " bgcolor=\"white\",\n",
2625
+ " )\n",
2626
+ "\n",
2627
+ "fig.show()"
2628
+ ]
2629
+ },
2630
+ {
2631
+ "cell_type": "code",
2632
+ "execution_count": 10,
2633
+ "metadata": {},
2634
+ "outputs": [
2635
+ {
2636
+ "data": {
2637
+ "text/plain": [
2638
+ "(array([ 6.82748858, 6.93282073, 7.16188991, 7.1146092 , 6.98378534,\n",
2639
+ " 7.20826381, 7.39959625, 7.39959625, 7.22352672, 6.94993037,\n",
2640
+ " 6.67929971, 6.93282073, 6.88073999, 7.06638224, 7.29843681,\n",
2641
+ " 7.20826381, 7.0500891 , 7.41371315, 7.69297573, 7.69297573,\n",
2642
+ " 7.5372583 , 7.17744676, 6.86312241, 7.28363791, 7.3567524 ,\n",
2643
+ " 7.42774956, 7.79166114, 7.60332502, 7.71801212, 7.79166114,\n",
2644
+ " 8.03379761, 8.03379761, 7.86322462, 7.59025116, 7.37111692,\n",
2645
+ " 7.64214072, 7.70552511, 7.81574099, 7.96692819, 7.82769554,\n",
2646
+ " 7.85143679, 8.23478318, 8.35415586, 8.46833523, 8.14152245,\n",
2647
+ " 7.94424459, 7.71801212, 7.97819498, 8.00058091, 8.00058091,\n",
2648
+ " 8.41186391, 8.40233336, 8.34441344, 8.47763088, 8.66568394,\n",
2649
+ " 8.73398059, 8.42136011, 8.16253865, 7.81574099, 8.05570584,\n",
2650
+ " 8.08822246, 7.9098368 , 8.40233336, 8.32481936, 8.3927682 ,\n",
2651
+ " 8.66568394, 8.9757346 , 8.90544135, 8.62209773, 8.34441344,\n",
2652
+ " 8.07742912, 8.34441344, 8.46833523, 8.38316815, 8.69149921,\n",
2653
+ " 8.70857243, 8.71706852, 9.07418213, 9.41661368, 9.30252135,\n",
2654
+ " 9.05177502, 8.75078704, 8.42136011, 8.78408875, 8.83328384,\n",
2655
+ " 8.77580178, 9.08901941, 9.05926438, 9.09640816, 9.48162253,\n",
2656
+ " 9.72178824, 9.67414826, 9.35679145, 9.00640452, 8.72553785,\n",
2657
+ " 9.00640452, 9.07418213, 8.96801306, 9.36350176, 9.30936305,\n",
2658
+ " 9.35679145, 9.77445246, 10.01358765, 10.02424443, 9.66813702,\n",
2659
+ " 9.30252135, 8.99876921, 9.22613239, 9.25415342, 9.09640816,\n",
2660
+ " 9.40342965, 9.30936305, 9.41002941, 9.84885828, 10.1491833 ,\n",
2661
+ " 10.21968053, 9.66813702, 9.38353677, 9.03673475, 9.23316418,\n",
2662
+ " 9.39018342, 9.26805875, 9.68014687, 9.61958525, 9.76283258,\n",
2663
+ " 10.05071724, 10.4262609 , 10.47688178, 10.00289175, 9.68613291,\n",
2664
+ " 9.40342965, 9.67414826, 9.74531406, 9.58881435, 9.75700495,\n",
2665
+ " 9.99215641, 10.05071724, 10.36530783, 10.75144927, 10.68404571,\n",
2666
+ " 10.23457009, 9.99215641, 9.58261997, 9.83185756]),\n",
2667
+ " 0.14802256973464573)"
2668
+ ]
2669
+ },
2670
+ "execution_count": 10,
2671
+ "metadata": {},
2672
+ "output_type": "execute_result"
2673
+ }
2674
+ ],
2675
+ "source": [
2676
+ "boxcox(data['#Passengers'])"
2677
+ ]
2678
+ },
2679
+ {
2680
+ "cell_type": "code",
2681
+ "execution_count": 11,
2682
+ "metadata": {},
2683
+ "outputs": [],
2684
+ "source": [
2685
+ "# Apply box-cox transform and plot it\n",
2686
+ "data['Passengers_box_cox'], lam = boxcox(data['#Passengers'])"
2687
+ ]
2688
+ },
2689
+ {
2690
+ "cell_type": "code",
2691
+ "execution_count": null,
2692
+ "metadata": {},
2693
+ "outputs": [],
2694
+ "source": [
2695
+ "plotting(title='Airline Passengers', data=data, x='Month', y='Passengers_box_cox',\n",
2696
+ " x_label='Date', y_label='Passengers<br>Box-Cox Transform', text=True, lam=lam)"
2697
+ ]
2698
+ }
2699
+ ],
2700
+ "metadata": {
2701
+ "kernelspec": {
2702
+ "display_name": "py311-kfp240-airflow251",
2703
+ "language": "python",
2704
+ "name": "python3"
2705
+ },
2706
+ "language_info": {
2707
+ "codemirror_mode": {
2708
+ "name": "ipython",
2709
+ "version": 3
2710
+ },
2711
+ "file_extension": ".py",
2712
+ "mimetype": "text/x-python",
2713
+ "name": "python",
2714
+ "nbconvert_exporter": "python",
2715
+ "pygments_lexer": "ipython3",
2716
+ "version": "3.11.5"
2717
+ }
2718
+ },
2719
+ "nbformat": 4,
2720
+ "nbformat_minor": 2
2721
+ }
coal-price-forecast.ipynb CHANGED
@@ -13,7 +13,7 @@
13
  },
14
  {
15
  "cell_type": "code",
16
- "execution_count": 2,
17
  "metadata": {},
18
  "outputs": [
19
  {
@@ -155,16 +155,23 @@
155
  "[145 rows x 5 columns]"
156
  ]
157
  },
158
- "execution_count": 2,
159
  "metadata": {},
160
  "output_type": "execute_result"
161
  }
162
  ],
163
  "source": [
164
- "df = pd.read_csv(\"../coal-price-data/coal_price_data.csv\")\n",
165
- "df"
166
  ]
167
  },
 
 
 
 
 
 
 
168
  {
169
  "cell_type": "code",
170
  "execution_count": 5,
 
13
  },
14
  {
15
  "cell_type": "code",
16
+ "execution_count": 3,
17
  "metadata": {},
18
  "outputs": [
19
  {
 
155
  "[145 rows x 5 columns]"
156
  ]
157
  },
158
+ "execution_count": 3,
159
  "metadata": {},
160
  "output_type": "execute_result"
161
  }
162
  ],
163
  "source": [
164
+ "df_coal = pd.read_csv(\"../coal-price-data/coal_price_data.csv\")\n",
165
+ "df_coal"
166
  ]
167
  },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": null,
171
+ "metadata": {},
172
+ "outputs": [],
173
+ "source": []
174
+ },
175
  {
176
  "cell_type": "code",
177
  "execution_count": 5,
cross_validation.ipynb CHANGED
@@ -2474,11 +2474,9 @@
2474
  "from sklearn.model_selection import KFold\n",
2475
  "\n",
2476
  "\n",
2477
- "def plot_cross_val(n_splits: int,\n",
2478
- " splitter_func,\n",
2479
- " df: pd.DataFrame,\n",
2480
- " title_text: str) -> None:\n",
2481
- " \n",
2482
  " \"\"\"Function to plot the cross validation of various\n",
2483
  " sklearn splitter objects.\"\"\"\n",
2484
  "\n",
@@ -2486,51 +2484,63 @@
2486
  " plot_data = []\n",
2487
  "\n",
2488
  " for train_index, valid_index in splitter_func(n_splits=n_splits).split(df):\n",
2489
- " plot_data.append([train_index, 'Train', f'{split}'])\n",
2490
- " plot_data.append([valid_index, 'Test', f'{split}'])\n",
2491
  " split += 1\n",
2492
  "\n",
2493
- " plot_df = pd.DataFrame(plot_data,\n",
2494
- " columns=['Index', 'Dataset', 'Split'])\\\n",
2495
- " .explode('Index')\n",
2496
  "\n",
2497
  " fig = go.Figure()\n",
2498
- " for _, group in plot_df.groupby('Split'):\n",
2499
- " fig.add_trace(go.Scatter(x=group['Index'].loc[group['Dataset'] == 'Train'],\n",
2500
- " y=group['Split'].loc[group['Dataset'] == 'Train'],\n",
2501
- " name='Train',\n",
2502
- " line=dict(color=\"blue\", width=10)\n",
2503
- " ))\n",
2504
- " fig.add_trace(go.Scatter(x=group['Index'].loc[group['Dataset'] == 'Test'],\n",
2505
- " y=group['Split'].loc[group['Dataset'] == 'Test'],\n",
2506
- " name='Test',\n",
2507
- " line=dict(color=\"goldenrod\", width=10)\n",
2508
- " ))\n",
 
 
 
 
 
 
2509
  "\n",
2510
- " fig.update_layout(template=\"simple_white\", font=dict(size=20),\n",
2511
- " title_text=title_text, title_x=0.5, width=850,\n",
2512
- " height=450, xaxis_title='Index', yaxis_title='Split')\n",
 
 
 
 
 
 
 
2513
  "\n",
2514
  " legend_names = set()\n",
2515
  " fig.for_each_trace(\n",
2516
- " lambda trace:\n",
2517
- " trace.update(showlegend=False)\n",
2518
- " if (trace.name in legend_names) else legend_names.add(trace.name))\n",
 
2519
  "\n",
2520
  " return fig.show()\n",
2521
- " \n",
2522
- " \n",
2523
- "if __name__ == \"__main__\":\n",
2524
  "\n",
 
 
2525
  " # Read in the data\n",
2526
- " data = pd.read_csv('../coal-price-data/AirPassengers.csv')\n",
2527
- " data['Month'] = pd.to_datetime(data['Month'])\n",
2528
- " \n",
2529
  " # Plot the cross validation\n",
2530
- " plot_cross_val(n_splits=5,\n",
2531
- " splitter_func=KFold,\n",
2532
- " df=data,\n",
2533
- " title_text='Cross-Validation')"
2534
  ]
2535
  },
2536
  {
@@ -4525,10 +4535,12 @@
4525
  "from sklearn.model_selection import TimeSeriesSplit\n",
4526
  "\n",
4527
  "# Plot the time series cross validation splits\n",
4528
- "plot_cross_val(n_splits=5,\n",
4529
- " splitter_func=TimeSeriesSplit,\n",
4530
- " df=data,\n",
4531
- " title_text='Time Series Cross-Validation')"
 
 
4532
  ]
4533
  },
4534
  {
@@ -5764,23 +5776,31 @@
5764
  "\n",
5765
  "def plot_time_series(df: pd.DataFrame) -> None:\n",
5766
  " \"\"\"General function to plot the passenger data.\"\"\"\n",
5767
- " \n",
5768
- " fig = px.line(df, x='Month', y='#Passengers',\n",
5769
- " labels={'Month': 'Date', '#Passengers': 'Passengers'})\n",
5770
- " \n",
5771
- " fig.update_layout(template=\"simple_white\", font=dict(size=18),\n",
5772
- " title_text='Airline Passengers', width=650,\n",
5773
- " title_x=0.5, height=400)\n",
 
 
 
 
 
 
 
 
 
5774
  "\n",
5775
  " return fig.show()\n",
5776
- " \n",
5777
- " \n",
5778
- "if __name__ == \"__main__\":\n",
5779
  "\n",
 
 
5780
  " # Read in the data\n",
5781
- " data = pd.read_csv('../coal-price-data/AirPassengers.csv')\n",
5782
- " data['Month'] = pd.to_datetime(data['Month'])\n",
5783
- " \n",
5784
  " # Plot the time series\n",
5785
  " plot_time_series(df=data)"
5786
  ]
@@ -5799,42 +5819,51 @@
5799
  "from statsmodels.tsa.holtwinters import ExponentialSmoothing\n",
5800
  "\n",
5801
  "\n",
5802
- "def hyperparameter_tuning_season_cv(n_splits: int,\n",
5803
- " gammas: list[float],\n",
5804
- " df: pd.DataFrame) -> pd.DataFrame: \n",
5805
  " \"\"\"Function to carry out cross-validation hyperparameter tuning\n",
5806
- " for the seasonal parameter in a Holt Winters' model. \"\"\"\n",
5807
  "\n",
5808
  " tscv = TimeSeriesSplit(n_splits=n_splits)\n",
5809
  " error_list = []\n",
5810
  "\n",
5811
  " for gamma in gammas:\n",
5812
- " \n",
5813
  " errors = []\n",
5814
- " \n",
5815
  " for train_index, valid_index in tscv.split(df):\n",
5816
  " train, valid = df.iloc[train_index], df.iloc[valid_index]\n",
5817
- " \n",
5818
- " model = ExponentialSmoothing(train['#Passengers'], trend='mul',\n",
5819
- " seasonal='mul', seasonal_periods=12) \\\n",
5820
- " .fit(smoothing_seasonal=gamma)\n",
5821
- " \n",
 
 
 
5822
  " forecasts = model.forecast(len(valid))\n",
5823
- " errors.append(mean_absolute_percentage_error(valid['#Passengers'], forecasts))\n",
 
 
5824
  "\n",
5825
  " error_list.append([gamma, sum(errors) / len(errors)])\n",
5826
  "\n",
5827
- " return pd.DataFrame(error_list, columns=['Gamma', 'MAPE'])\n",
5828
- " \n",
5829
- " \n",
5830
- "def plot_error_cv(df: pd.DataFrame,\n",
5831
- " title: str) -> None: \n",
5832
  " \"\"\"Bar chart to plot the errors from the different\n",
5833
  " hyperparameters.\"\"\"\n",
5834
  "\n",
5835
- " fig = px.bar(df, x='Gamma', y='MAPE')\n",
5836
- " fig.update_layout(template=\"simple_white\", font=dict(size=18), title_text=title,\n",
5837
- " width=800, title_x=0.5, height=400)\n",
 
 
 
 
 
 
5838
  "\n",
5839
  " return fig.show()"
5840
  ]
@@ -5846,8 +5875,8 @@
5846
  "outputs": [],
5847
  "source": [
5848
  "# Read in the data\n",
5849
- "data = pd.read_csv('../coal-price-data/AirPassengers.csv')\n",
5850
- "data['Month'] = pd.to_datetime(data['Month'])"
5851
  ]
5852
  },
5853
  {
@@ -5980,9 +6009,9 @@
5980
  ],
5981
  "source": [
5982
  "# Carry out cv for hyperparameter tuning for the seasonal parameter\n",
5983
- "error_df = hyperparameter_tuning_season_cv(df=data,\n",
5984
- " n_splits=4,\n",
5985
- " gammas=list(np.arange(0, 1.1, 0.1)))"
5986
  ]
5987
  },
5988
  {
@@ -7062,7 +7091,7 @@
7062
  ],
7063
  "source": [
7064
  "# Plot the tuning results\n",
7065
- "plot_error_cv(df=error_df, title='Hyperparameter Results')"
7066
  ]
7067
  },
7068
  {
 
2474
  "from sklearn.model_selection import KFold\n",
2475
  "\n",
2476
  "\n",
2477
+ "def plot_cross_val(\n",
2478
+ " n_splits: int, splitter_func, df: pd.DataFrame, title_text: str\n",
2479
+ ") -> None:\n",
 
 
2480
  " \"\"\"Function to plot the cross validation of various\n",
2481
  " sklearn splitter objects.\"\"\"\n",
2482
  "\n",
 
2484
  " plot_data = []\n",
2485
  "\n",
2486
  " for train_index, valid_index in splitter_func(n_splits=n_splits).split(df):\n",
2487
+ " plot_data.append([train_index, \"Train\", f\"{split}\"])\n",
2488
+ " plot_data.append([valid_index, \"Test\", f\"{split}\"])\n",
2489
  " split += 1\n",
2490
  "\n",
2491
+ " plot_df = pd.DataFrame(\n",
2492
+ " plot_data, columns=[\"Index\", \"Dataset\", \"Split\"]\n",
2493
+ " ).explode(\"Index\")\n",
2494
  "\n",
2495
  " fig = go.Figure()\n",
2496
+ " for _, group in plot_df.groupby(\"Split\"):\n",
2497
+ " fig.add_trace(\n",
2498
+ " go.Scatter(\n",
2499
+ " x=group[\"Index\"].loc[group[\"Dataset\"] == \"Train\"],\n",
2500
+ " y=group[\"Split\"].loc[group[\"Dataset\"] == \"Train\"],\n",
2501
+ " name=\"Train\",\n",
2502
+ " line=dict(color=\"blue\", width=10),\n",
2503
+ " )\n",
2504
+ " )\n",
2505
+ " fig.add_trace(\n",
2506
+ " go.Scatter(\n",
2507
+ " x=group[\"Index\"].loc[group[\"Dataset\"] == \"Test\"],\n",
2508
+ " y=group[\"Split\"].loc[group[\"Dataset\"] == \"Test\"],\n",
2509
+ " name=\"Test\",\n",
2510
+ " line=dict(color=\"goldenrod\", width=10),\n",
2511
+ " )\n",
2512
+ " )\n",
2513
  "\n",
2514
+ " fig.update_layout(\n",
2515
+ " template=\"simple_white\",\n",
2516
+ " font=dict(size=20),\n",
2517
+ " title_text=title_text,\n",
2518
+ " title_x=0.5,\n",
2519
+ " width=850,\n",
2520
+ " height=450,\n",
2521
+ " xaxis_title=\"Index\",\n",
2522
+ " yaxis_title=\"Split\",\n",
2523
+ " )\n",
2524
  "\n",
2525
  " legend_names = set()\n",
2526
  " fig.for_each_trace(\n",
2527
+ " lambda trace: trace.update(showlegend=False)\n",
2528
+ " if (trace.name in legend_names)\n",
2529
+ " else legend_names.add(trace.name)\n",
2530
+ " )\n",
2531
  "\n",
2532
  " return fig.show()\n",
 
 
 
2533
  "\n",
2534
+ "\n",
2535
+ "if __name__ == \"__main__\":\n",
2536
  " # Read in the data\n",
2537
+ " data = pd.read_csv(\"../coal-price-data/AirPassengers.csv\")\n",
2538
+ " data[\"Month\"] = pd.to_datetime(data[\"Month\"])\n",
2539
+ "\n",
2540
  " # Plot the cross validation\n",
2541
+ " plot_cross_val(\n",
2542
+ " n_splits=5, splitter_func=KFold, df=data, title_text=\"Cross-Validation\"\n",
2543
+ " )"
 
2544
  ]
2545
  },
2546
  {
 
4535
  "from sklearn.model_selection import TimeSeriesSplit\n",
4536
  "\n",
4537
  "# Plot the time series cross validation splits\n",
4538
+ "plot_cross_val(\n",
4539
+ " n_splits=5,\n",
4540
+ " splitter_func=TimeSeriesSplit,\n",
4541
+ " df=data,\n",
4542
+ " title_text=\"Time Series Cross-Validation\",\n",
4543
+ ")"
4544
  ]
4545
  },
4546
  {
 
5776
  "\n",
5777
  "def plot_time_series(df: pd.DataFrame) -> None:\n",
5778
  " \"\"\"General function to plot the passenger data.\"\"\"\n",
5779
+ "\n",
5780
+ " fig = px.line(\n",
5781
+ " df,\n",
5782
+ " x=\"Month\",\n",
5783
+ " y=\"#Passengers\",\n",
5784
+ " labels={\"Month\": \"Date\", \"#Passengers\": \"Passengers\"},\n",
5785
+ " )\n",
5786
+ "\n",
5787
+ " fig.update_layout(\n",
5788
+ " template=\"simple_white\",\n",
5789
+ " font=dict(size=18),\n",
5790
+ " title_text=\"Airline Passengers\",\n",
5791
+ " width=650,\n",
5792
+ " title_x=0.5,\n",
5793
+ " height=400,\n",
5794
+ " )\n",
5795
  "\n",
5796
  " return fig.show()\n",
 
 
 
5797
  "\n",
5798
+ "\n",
5799
+ "if __name__ == \"__main__\":\n",
5800
  " # Read in the data\n",
5801
+ " data = pd.read_csv(\"../coal-price-data/AirPassengers.csv\")\n",
5802
+ " data[\"Month\"] = pd.to_datetime(data[\"Month\"])\n",
5803
+ "\n",
5804
  " # Plot the time series\n",
5805
  " plot_time_series(df=data)"
5806
  ]
 
5819
  "from statsmodels.tsa.holtwinters import ExponentialSmoothing\n",
5820
  "\n",
5821
  "\n",
5822
+ "def hyperparameter_tuning_season_cv(\n",
5823
+ " n_splits: int, gammas: list[float], df: pd.DataFrame\n",
5824
+ ") -> pd.DataFrame:\n",
5825
  " \"\"\"Function to carry out cross-validation hyperparameter tuning\n",
5826
+ " for the seasonal parameter in a Holt Winters' model.\"\"\"\n",
5827
  "\n",
5828
  " tscv = TimeSeriesSplit(n_splits=n_splits)\n",
5829
  " error_list = []\n",
5830
  "\n",
5831
  " for gamma in gammas:\n",
 
5832
  " errors = []\n",
5833
+ "\n",
5834
  " for train_index, valid_index in tscv.split(df):\n",
5835
  " train, valid = df.iloc[train_index], df.iloc[valid_index]\n",
5836
+ "\n",
5837
+ " model = ExponentialSmoothing(\n",
5838
+ " train[\"#Passengers\"],\n",
5839
+ " trend=\"mul\",\n",
5840
+ " seasonal=\"mul\",\n",
5841
+ " seasonal_periods=12,\n",
5842
+ " ).fit(smoothing_seasonal=gamma)\n",
5843
+ "\n",
5844
  " forecasts = model.forecast(len(valid))\n",
5845
+ " errors.append(\n",
5846
+ " mean_absolute_percentage_error(valid[\"#Passengers\"], forecasts)\n",
5847
+ " )\n",
5848
  "\n",
5849
  " error_list.append([gamma, sum(errors) / len(errors)])\n",
5850
  "\n",
5851
+ " return pd.DataFrame(error_list, columns=[\"Gamma\", \"MAPE\"])\n",
5852
+ "\n",
5853
+ "\n",
5854
+ "def plot_error_cv(df: pd.DataFrame, title: str) -> None:\n",
 
5855
  " \"\"\"Bar chart to plot the errors from the different\n",
5856
  " hyperparameters.\"\"\"\n",
5857
  "\n",
5858
+ " fig = px.bar(df, x=\"Gamma\", y=\"MAPE\")\n",
5859
+ " fig.update_layout(\n",
5860
+ " template=\"simple_white\",\n",
5861
+ " font=dict(size=18),\n",
5862
+ " title_text=title,\n",
5863
+ " width=800,\n",
5864
+ " title_x=0.5,\n",
5865
+ " height=400,\n",
5866
+ " )\n",
5867
  "\n",
5868
  " return fig.show()"
5869
  ]
 
5875
  "outputs": [],
5876
  "source": [
5877
  "# Read in the data\n",
5878
+ "data = pd.read_csv(\"../coal-price-data/AirPassengers.csv\")\n",
5879
+ "data[\"Month\"] = pd.to_datetime(data[\"Month\"])"
5880
  ]
5881
  },
5882
  {
 
6009
  ],
6010
  "source": [
6011
  "# Carry out cv for hyperparameter tuning for the seasonal parameter\n",
6012
+ "error_df = hyperparameter_tuning_season_cv(\n",
6013
+ " df=data, n_splits=4, gammas=list(np.arange(0, 1.1, 0.1))\n",
6014
+ ")"
6015
  ]
6016
  },
6017
  {
 
7091
  ],
7092
  "source": [
7093
  "# Plot the tuning results\n",
7094
+ "plot_error_cv(df=error_df, title=\"Hyperparameter Results\")"
7095
  ]
7096
  },
7097
  {
multiple_timeseries_forecast.ipynb CHANGED
The diff for this file is too large to render. See raw diff