13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 | def fetch_dataset(
name: str,
version: str = 'latest',
raw: bool = False,
kwargs_read_csv: dict = {},
verbose: bool = True
) -> pd.DataFrame:
"""
Fetch a dataset from the skforecast-datasets repository.
Parameters
----------
name: str
Name of the dataset to fetch.
version: str, int, default `'latest'`
Version of the dataset to fetch. If 'latest', the lastest version will be
fetched (the one in the main branch). For a list of available versions,
see the repository branches.
raw: bool, default `False`
If True, the raw dataset is fetched. If False, the preprocessed dataset
is fetched. The preprocessing consists of setting the column with the
date/time as index and converting the index to datetime. A frequency is
also set to the index.
kwargs_read_csv: dict, default `{}`
Kwargs to pass to pandas `read_csv` function.
verbose: bool, default `True`
If True, print information about the dataset.
Returns
-------
df: pandas DataFrame
Dataset.
"""
version = 'main' if version == 'latest' else f'{version}'
datasets = {
'h2o': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/h2o.csv'
),
'sep': ',',
'index_col': 'fecha',
'date_format': '%Y-%m-%d',
'freq': 'MS',
'description': (
'Monthly expenditure ($AUD) on corticosteroid drugs that the '
'Australian health system had between 1991 and 2008. '
),
'source': (
'Hyndman R (2023). fpp3: Data for Forecasting: Principles and Practice'
'(3rd Edition). http://pkg.robjhyndman.com/fpp3package/,'
'https://github.com/robjhyndman/fpp3package, http://OTexts.com/fpp3.'
)
},
'h2o_exog': {
'url': (
f"https://raw.githubusercontent.com/JoaquinAmatRodrigo/"
f"skforecast-datasets/{version}/data/h2o_exog.csv"
),
'sep': ',',
'index_col': 'fecha',
'date_format': '%Y-%m-%d',
'freq': 'MS',
'description': (
'Monthly expenditure ($AUD) on corticosteroid drugs that the '
'Australian health system had between 1991 and 2008. Two additional '
'variables (exog_1, exog_2) are simulated.'
),
'source': (
"Hyndman R (2023). fpp3: Data for Forecasting: Principles and Practice "
"(3rd Edition). http://pkg.robjhyndman.com/fpp3package/, "
"https://github.com/robjhyndman/fpp3package, http://OTexts.com/fpp3."
)
},
'fuel_consumption': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/consumos-combustibles-mensual.csv'
),
'sep': ',',
'index_col': 'Fecha',
'date_format': '%Y-%m-%d',
'freq': 'MS',
'description': (
'Monthly fuel consumption in Spain from 1969-01-01 to 2022-08-01.'
),
'source': (
'Obtained from Corporación de Reservas Estratégicas de Productos '
'Petrolíferos and Corporación de Derecho Público tutelada por el '
'Ministerio para la Transición Ecológica y el Reto Demográfico. '
'https://www.cores.es/es/estadisticas'
)
},
'items_sales': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/simulated_items_sales.csv'
),
'sep': ',',
'index_col': 'date',
'date_format': '%Y-%m-%d',
'freq': 'D',
'description': 'Simulated time series for the sales of 3 different items.',
'source': 'Simulated data.'
},
'air_quality_valencia': {
'url': (
f"https://raw.githubusercontent.com/JoaquinAmatRodrigo/"
f"skforecast-datasets/{version}/data/air_quality_valencia.csv"
),
'sep': ',',
'index_col': 'datetime',
'date_format': '%Y-%m-%d %H:%M:%S',
'freq': 'H',
'description': (
'Hourly measures of several air chemical pollutant (pm2.5, co, no, '
'no2, pm10, nox, o3, so2) at Valencia city.'
),
'source': (
" Red de Vigilancia y Control de la Contaminación Atmosférica, "
"46250054-València - Centre, "
"https://mediambient.gva.es/es/web/calidad-ambiental/datos-historicos."
)
},
'website_visits': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/visitas_por_dia_web_cienciadedatos.csv'
),
'sep': ',',
'index_col': 'date',
'date_format': '%Y-%m-%d',
'freq': '1D',
'description': (
'Daily visits to the cienciadedatos.net website registered with the '
'google analytics service.'
),
'source': (
"Amat Rodrigo, J. (2021). cienciadedatos.net (1.0.0). Zenodo. "
"https://doi.org/10.5281/zenodo.10006330"
)
},
'bike_sharing': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/bike_sharing_dataset_clean.csv'
),
'sep': ',',
'index_col': 'date_time',
'date_format': '%Y-%m-%d %H:%M:%S',
'freq': 'H',
'description': (
'Hourly usage of the bike share system in the city of Washington D.C. '
'during the years 2011 and 2012. In addition to the number of users per '
'hour, information about weather conditions and holidays is available.'
),
'source': (
"Fanaee-T,Hadi. (2013). Bike Sharing Dataset. UCI Machine Learning "
"Repository. https://doi.org/10.24432/C5W894."
)
},
'bike_sharing_extended_features': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/bike_sharing_extended_features.csv'
),
'sep': ',',
'index_col': 'date_time',
'date_format': '%Y-%m-%d %H:%M:%S',
'freq': 'H',
'description': (
'Hourly usage of the bike share system in the city of Washington D.C. '
'during the years 2011 and 2012. In addition to the number of users per '
'hour, the dataset was enriched by introducing supplementary features. '
'Addition includes calendar-based variables (day of the week, hour of '
'the day, month, etc.), indicators for sunlight, incorporation of '
'rolling temperature averages, and the creation of polynomial features '
'generated from variable pairs. All cyclic variables are encoded using '
'sine and cosine functions to ensure accurate representation.'
),
'source': (
"Fanaee-T,Hadi. (2013). Bike Sharing Dataset. UCI Machine Learning "
"Repository. https://doi.org/10.24432/C5W894."
)
},
'australia_tourism': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/australia_tourism.csv'
),
'sep': ',',
'index_col': 'date_time',
'date_format': '%Y-%m-%d',
'freq': 'Q',
'description': (
"Quarterly overnight trips (in thousands) from 1998 Q1 to 2016 Q4 "
"across Australia. The tourism regions are formed through the "
"aggregation of Statistical Local Areas (SLAs) which are defined by "
"the various State and Territory tourism authorities according to "
"their research and marketing needs."
),
'source': (
"Wang, E, D Cook, and RJ Hyndman (2020). A new tidy data structure to "
"support exploration and modeling of temporal data, Journal of "
"Computational and Graphical Statistics, 29:3, 466-478, "
"doi:10.1080/10618600.2019.1695624."
)
},
'uk_daily_flights': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/uk_daily_flights.csv'
),
'sep': ',',
'index_col': 'Date',
'date_format': '%d/%m/%Y',
'freq': 'D',
'description': 'Daily number of flights in UK from 02/01/2019 to 23/01/2022.',
'source': (
'Experimental statistics published as part of the Economic activity and '
'social change in the UK, real-time indicators release, Published 27 '
'January 2022. Daily flight numbers are available in the dashboard '
'provided by the European Organisation for the Safety of Air Navigation '
'(EUROCONTROL). '
'https://www.ons.gov.uk/economy/economicoutputandproductivity/output/'
'bulletins/economicactivityandsocialchangeintheukrealtimeindicators/latest'
)
},
'wikipedia_visits': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/wikipedia_visits.csv'
),
'sep': ',',
'index_col': 'date',
'date_format': '%Y-%m-%d',
'freq': 'D',
'description': (
'Log daily page views for the Wikipedia page for Peyton Manning. '
'Scraped data using the Wikipediatrend package in R.'
),
'source': (
'https://github.com/facebook/prophet/blob/main/examples/'
'example_wp_log_peyton_manning.csv'
)
},
'vic_electricity': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/vic_electricity.csv'
),
'sep': ',',
'index_col': 'Time',
'date_format': '%Y-%m-%dT%H:%M:%SZ',
'freq': '30min',
'description': 'Half-hourly electricity demand for Victoria, Australia',
'source': (
"O'Hara-Wild M, Hyndman R, Wang E, Godahewa R (2022).tsibbledata: Diverse "
"Datasets for 'tsibble'. https://tsibbledata.tidyverts.org/, "
"https://github.com/tidyverts/tsibbledata/. "
"https://tsibbledata.tidyverts.org/reference/vic_elec.html"
)
},
'store_sales': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/store_sales.csv'
),
'sep': ',',
'index_col': 'date',
'date_format': '%Y-%m-%d',
'freq': 'D',
'description': (
'This dataset contains 913,000 sales transactions from 2013-01-01 to '
'2017-12-31 for 50 products (SKU) in 10 stores.'
),
'source': (
'The original data was obtained from: inversion. (2018). Store Item '
'Demand Forecasting Challenge. Kaggle. '
'https://kaggle.com/competitions/demand-forecasting-kernels-only'
)
},
'bicimad': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/bicimad_users.csv'
),
'sep': ',',
'index_col': 'date',
'date_format': '%Y-%m-%d',
'freq': 'D',
'description': (
'This dataset contains the daily users of the bicycle rental '
'service (BiciMad) in the city of Madrid (Spain) from 2014-06-23 '
'to 2022-09-30.'
),
'source': (
'The original data was obtained from: Portal de datos abiertos '
'del Ayuntamiento de Madrid https://datos.madrid.es/portal/site/egob'
)
},
'm4_hourly': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/m4_hourly.parquet'
),
'sep': None,
'index_col': 'timestamp',
'date_format': '%Y-%m-%d %H:%M:%S',
'freq': 'H',
'description': "Time series with hourly frequency from the M4 competition.",
'source': (
"Monash Time Series Forecasting Repository "
"(https://zenodo.org/communities/forecasting) Godahewa, R., Bergmeir, "
"C., Webb, G. I., Hyndman, R. J., & Montero-Manso, P. (2021). Monash "
"Time Series Forecasting Archive. In Neural Information Processing "
"Systems Track on Datasets and Benchmarks. \n"
"Raw data, available in .tsf format, has been converted to Pandas "
"format using the code provided by the authors in "
"https://github.com/rakshitha123/TSForecasting/blob/master/utils/data_loader.py \n"
"The category of each time series has been included in the dataset. This "
"information has been obtainded from the Kaggle competition page: "
"https://www.kaggle.com/datasets/yogesh94/m4-forecasting-competition-dataset"
)
},
'm4_daily': {
'url': (
f'https://raw.githubusercontent.com/JoaquinAmatRodrigo/'
f'skforecast-datasets/{version}/data/m4_daily.parquet'
),
'sep': None,
'index_col': 'timestamp',
'date_format': '%Y-%m-%d %H:%M:%S',
'freq': 'D',
'description': "Time series with daily frequency from the M4 competition.",
'source': (
"Monash Time Series Forecasting Repository "
"(https://zenodo.org/communities/forecasting) Godahewa, R., Bergmeir, "
"C., Webb, G. I., Hyndman, R. J., & Montero-Manso, P. (2021). Monash "
"Time Series Forecasting Archive. In Neural Information Processing "
"Systems Track on Datasets and Benchmarks. \n"
"Raw data, available in .tsf format, has been converted to Pandas "
"format using the code provided by the authors in "
"https://github.com/rakshitha123/TSForecasting/blob/master/utils/data_loader.py \n"
"The category of each time series has been included in the dataset. This "
"information has been obtainded from the Kaggle competition page: "
"https://www.kaggle.com/datasets/yogesh94/m4-forecasting-competition-dataset"
)
},
'ashrae_daily': {
'url': 'https://drive.google.com/file/d/1fMsYjfhrFLmeFjKG3jenXjDa5s984ThC/view?usp=sharing',
'sep': None,
'index_col': 'timestamp',
'date_format': '%Y-%m-%d',
'freq': 'D',
'description': (
"Daily energy consumption data from the ASHRAE competition with "
"building metadata and weather data."
),
'source': (
"Kaggle competition Addison Howard, Chris Balbach, Clayton Miller, "
"Jeff Haberl, Krishnan Gowri, Sohier Dane. (2019). ASHRAE - Great Energy "
"Predictor III. Kaggle. https://www.kaggle.com/c/ashrae-energy-prediction/overview"
)
},
'bdg2_daily': {
'url': 'https://drive.google.com/file/d/1KHYopzclKvS1F6Gt6GoJWKnxiuZ2aqen/view?usp=sharing',
'sep': None,
'index_col': 'timestamp',
'date_format': '%Y-%m-%d',
'freq': 'D',
'description': (
"Daily energy consumption data from the The Building Data Genome Project 2 "
"with building metadata and weather data. "
"https://github.com/buds-lab/building-data-genome-project-2"
),
'source': (
"Miller, C., Kathirgamanathan, A., Picchetti, B. et al. The Building Data "
"Genome Project 2, energy meter data from the ASHRAE Great Energy "
"Predictor III competition. Sci Data 7, 368 (2020). "
"https://doi.org/10.1038/s41597-020-00712-x"
)
},
'bdg2_hourly': {
'url': 'https://drive.google.com/file/d/1I2i5mZJ82Cl_SHPTaWJmLoaXnntdCgh7/view?usp=sharing',
'sep': None,
'index_col': 'timestamp',
'date_format': '%Y-%m-%d %H:%M:%S',
'freq': 'D',
'description': (
"Hourly energy consumption data from the The Building Data Genome Project 2 "
"with building metadata and weather data. "
"https://github.com/buds-lab/building-data-genome-project-2"
),
'source': (
"Miller, C., Kathirgamanathan, A., Picchetti, B. et al. The Building Data "
"Genome Project 2, energy meter data from the ASHRAE Great Energy "
"Predictor III competition. Sci Data 7, 368 (2020). "
"https://doi.org/10.1038/s41597-020-00712-x"
)
}
}
if name not in datasets.keys():
raise ValueError(
f"Dataset '{name}' not found. Available datasets are: {list(datasets.keys())}"
)
url = datasets[name]['url']
if url.endswith('.csv'):
try:
sep = datasets[name]['sep']
df = pd.read_csv(url, sep=sep, **kwargs_read_csv)
except:
raise ValueError(
f"Error reading dataset '{name}' from {url}. Try to version = 'latest'"
)
if url.endswith('.parquet'):
try:
df = pd.read_parquet(url)
except:
raise ValueError(
f"Error reading dataset '{name}' from {url}. Try to version = 'latest'"
)
if url.startswith('https://drive.google.com'):
file_id = url.split('/')[-2]
url = 'https://drive.google.com/uc?id=' + file_id
df = pd.read_parquet(url)
if not raw:
try:
index_col = datasets[name]['index_col']
freq = datasets[name]['freq']
if freq == 'H' and pd.__version__ >= '2.2.0':
freq = "h"
date_format = datasets[name]['date_format']
df = df.set_index(index_col)
df.index = pd.to_datetime(df.index, format=date_format)
df = df.asfreq(freq)
df = df.sort_index()
except:
pass
if verbose:
print(name)
print('-' * len(name))
description = textwrap.fill(datasets[name]['description'], width=80)
source = textwrap.fill(datasets[name]['source'], width=80)
print(description)
print(source)
print(f"Shape of the dataset: {df.shape}")
return df
|