-
Notifications
You must be signed in to change notification settings - Fork 89
/
_single_problem_loaders.py
1144 lines (959 loc) · 36.7 KB
/
_single_problem_loaders.py
1
2
3
4
5
6
7
8
9
10
11
12
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""Utilities for loading datasets."""
__author__ = [
"mloning",
"sajaysurya",
"big-o",
"SebasKoel",
"Emiliathewolf",
"TonyBagnall",
"yairbeer",
"patrickZIB",
"aiwalter",
"jasonlines",
"achieveordie",
"ciaran-g",
]
__all__ = [
"load_airline",
"load_plaid",
"load_arrow_head",
"load_gunpoint",
"load_osuleaf",
"load_italy_power_demand",
"load_basic_motions",
"load_japanese_vowels",
"load_solar",
"load_shampoo_sales",
"load_longley",
"load_lynx",
"load_acsf1",
"load_unit_test",
"load_uschange",
"load_PBS_dataset",
"load_gun_point_segmentation",
"load_electric_devices_segmentation",
"load_macroeconomic",
"load_unit_test_tsf",
"load_covid_3month",
]
import os
from urllib.error import HTTPError, URLError
from warnings import warn
import numpy as np
import pandas as pd
from aeon.datasets._data_loaders import _load_saved_dataset, _load_tsc_dataset
from aeon.datasets._dataframe_loaders import load_tsf_to_dataframe
from aeon.utils.validation._dependencies import _check_soft_dependencies
DIRNAME = "data"
MODULE = os.path.dirname(__file__)
def load_gunpoint(split=None, return_X_y=True, return_type="numpy3d"):
"""Load the GunPoint univariate time series classification problem.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure to use for time series, should be either "numpy2d" or "numpy3d".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: np.ndarray
shape (n_cases, 1, 150) (return_type="numpy3d") or shape (n_cases,
150) (return_type="numpy2d"), where n_cases is either 150 (split="train" or
"test") or 300.
y: np.ndarray
1D array of length 150 or 300, only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_gunpoint
>>> X, y = load_gunpoint()
Notes
-----
Dimensionality: univariate
Series length: 150
Train cases: 50
Test cases: 150
Number of classes: 2
Details: http://timeseriesclassification.com/description.php?Dataset=GunPoint
"""
return _load_tsc_dataset("GunPoint", split, return_X_y, return_type=return_type)
def load_osuleaf(split=None, return_X_y=True, return_type="numpy3d"):
"""Load the OSULeaf univariate time series classification problem.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure to use for time series, should be either "numpy2d" or "numpy3d".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: np.ndarray
shape (n_cases, 1, 427) (return_type="numpy3d") or shape (n_cases,
427) (return_type="numpy2d"), where n_cases where n_cases is either 200
(split = "train") 242 (split="test") or 442.
y: np.ndarray
1D array of length 200, 242 or 542, only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_osuleaf
>>> X, y = load_osuleaf()
Notes
-----
Dimensionality: univariate
Series length: 427
Train cases: 200
Test cases: 242
Number of classes: 6
Details: http://www.timeseriesclassification.com/description.php?Dataset=OSULeaf
"""
return _load_tsc_dataset("OSULeaf", split, return_X_y, return_type=return_type)
def load_italy_power_demand(split=None, return_X_y=True, return_type="numpy3d"):
"""Load ItalyPowerDemand univariate time series classification problem.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure to use for time series, should be either "numpy2d" or "numpy3d".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: np.ndarray
shape (n_cases, 1, 24) (return_type="numpy3d") or shape (n_cases,
24) (return_type="numpy2d"), where n_cases where n_cases is either 67
(split = "train") 1029 (split="test") or 1096.
y: np.ndarray
1D array of length 67, 1029 or 1096, only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_italy_power_demand
>>> X, y = load_italy_power_demand()
Notes
-----
Dimensionality: univariate
Series length: 24
Train cases: 67
Test cases: 1029
Number of classes: 2
Details:http://timeseriesclassification.com/description.php?Dataset=ItalyPowerDemand
"""
name = "ItalyPowerDemand"
return _load_tsc_dataset(name, split, return_X_y, return_type=return_type)
def load_unit_test(split=None, return_X_y=True, return_type="numpy3d"):
"""
Load UnitTest data.
This is an equal length univariate time series classification problem. It is a
stripped down version of the ChinaTown problem that is used in correctness tests
for classification.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure containing series, should be either "numpy2d" or "numpy3d".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: np.ndarray
shape (n_cases, 1, 24) (return_type="numpy3d) or shape (n_cases,
24) (return_type="numpy2d), where n_cases where n_cases is either 20
(split = "train") 22 (split="test") or 42.
y: np.ndarray
1D array of length 20, 22 or 42, only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_unit_test
>>> X, y = load_unit_test()
Details
-------
This is the Chinatown problem with a smaller test set, useful for rapid tests.
Dimensionality: univariate
Series length: 24
Train cases: 20
Test cases: 22 (full dataset has 345)
Number of classes: 2
Details: http://timeseriesclassification.com/description.php?Dataset=Chinatown
for the full dataset
"""
return _load_saved_dataset("UnitTest", split, return_X_y, return_type)
def load_arrow_head(split=None, return_X_y=True, return_type="numpy3d"):
"""
Load the ArrowHead univariate time series classification problem.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure to use for time series, should be either "numpy2d" or "numpy3d".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X:np.ndarray
shape (n_cases, 1, 251) (if return_type="numpy3d") or shape (n_cases,
251) (return_type="numpy2d"), where n_cases where n_cases is either 36
(split = "train"), 175 (split="test") or 211.
y: np.ndarray
1D array of length 36, 175 or 211, only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_arrow_head
>>> X, y = load_arrow_head()
Notes
-----
Dimensionality: univariate
Series length: 251
Train cases: 36
Test cases: 175
Number of classes: 3
Details: http://timeseriesclassification.com/description.php?Dataset=ArrowHead
"""
return _load_saved_dataset(
name="ArrowHead", split=split, return_X_y=return_X_y, return_type=return_type
)
def load_acsf1(split=None, return_X_y=True, return_type="numpy3d"):
"""Load the ACSF1 univariate dataset on power consumption of typical appliances.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure to use for time series, should be either "numpy2d" or "numpy3d".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: np.ndarray
shape (n_cases, 1, 1460) (if return_type="numpy3d") or shape (n_cases,
1460) (return_type="numpy2d"), where n_cases where n_cases is either 100
(split = "train" or split="test") or 200.
y: np.ndarray
1D array of length 100 or 200 only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_acsf1
>>> X, y = load_acsf1()
Notes
-----
Dimensionality: univariate
Series length: 1460
Train cases: 100
Test cases: 100
Number of classes: 10
Details: http://www.timeseriesclassification.com/description.php?Dataset=ACSF1
"""
return _load_tsc_dataset("ACSF1", split, return_X_y, return_type=return_type)
def load_basic_motions(split=None, return_X_y=True, return_type="numpy3d"):
"""
Load the BasicMotions time series classification problem.
Example of a multivariate problem with equal length time series.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, optional (default="numpy3d")
Data structure to use for time series, should be "numpy3d" or "np-list".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: np.ndarray
shape (n_cases, 6, 100) (if return_type="numpy3d"), where n_cases where
n_cases is either 40 (split = "train" or split="test") or 80.
y: np.ndarray
1D array of length 40 or 80, only returned if return_X_y is True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Notes
-----
Dimensionality: multivariate, 6
Series length: 100
Train cases: 40
Test cases: 40
Number of classes: 4
Details:http://www.timeseriesclassification.com/description.php?Dataset=BasicMotions
"""
if return_type == "numpy2d" or return_type == "numpyflat":
raise ValueError(
f"BasicMotions loader: Error, attempting to load into a {return_type} "
f"array, but cannot because it is a multivariate problem. Use "
f"numpy3d instead"
)
return _load_saved_dataset(
name="BasicMotions", split=split, return_X_y=return_X_y, return_type=return_type
)
def load_plaid(split=None, return_X_y=True, return_type="np-list"):
"""Load the PLAID univariate time series classification problem.
Example of a univariate problem with unequal length time series.
Parameters
----------
split: None or one of "TRAIN", "TEST", default=None
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, default=True
If True, returns (features, target) separately instead of as single data
structure.
return_type: string, default="np-list"
Data structure to use for time series, should be "nested_univ" or "np-list".
Raises
------
ValueError is raised if the data cannot be stored in the requested return_type.
Returns
-------
X: list of 2D np.ndarray, one for each series.
y: 1D numpy array of length n, only returned if return_X_y if True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Notes
-----
Dimensionality: univariate
Series length: variable
Train cases: 537
Test cases: 537
Number of classes: 2
Details: http://timeseriesclassification.com/description.php?Dataset=PLAID
Examples
--------
>>> from aeon.datasets import load_plaid
>>> X, y = load_plaid()
"""
return _load_tsc_dataset("PLAID", split, return_X_y, return_type=return_type)
def load_japanese_vowels(split=None, return_X_y=True, return_type="np-list"):
"""Load the JapaneseVowels time series classification problem.
Example of a multivariate problem with unequal length series.
Parameters
----------
split: None or one of "TRAIN", "TEST", optional (default=None)
Whether to load the train or test instances of the problem. By default it
loads both train and test instances into a single array.
return_X_y: bool, optional (default=True)
If True, returns (features, target) separately instead of a single
dataframe with columns for features and the target.
return_type: string, default="np-list"
Data structure to use for time series, should be "nested_univ" or "np-list".
Returns
-------
X: np.Pandas dataframe with 12 columns and a pd.Series in each cell
y: 1D numpy array of length n, only returned if return_X_y if True
The class labels for each time series instance in X
If return_X_y is False, y is appended to X instead.
Examples
--------
>>> from aeon.datasets import load_japanese_vowels
>>> X, y = load_japanese_vowels()
Notes
-----
Dimensionality: 12
Series length: variable (7-29)
Train cases: 270
Test cases: 370
Number of classes: 9
Details: http://timeseriesclassification.com/description.php?Dataset=JapaneseVowels
"""
return _load_tsc_dataset(
"JapaneseVowels", split, return_X_y, return_type=return_type
)
# forecasting data sets
def load_shampoo_sales():
"""Load the shampoo sales univariate time series dataset for forecasting.
Returns
-------
y : pd.Series/DataFrame
Shampoo sales dataset
Examples
--------
>>> from aeon.datasets import load_shampoo_sales
>>> y = load_shampoo_sales()
Notes
-----
This dataset describes the monthly number of sales of shampoo over a 3
year period.
The units are a sales count.
Dimensionality: univariate
Series length: 36
Frequency: Monthly
Number of cases: 1
References
----------
.. [1] Makridakis, Wheelwright and Hyndman (1998) Forecasting: methods
and applications,
John Wiley & Sons: New York. Chapter 3.
"""
name = "ShampooSales"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
y = pd.read_csv(path, index_col=0, dtype={1: float}).squeeze("columns")
y.index = pd.PeriodIndex(y.index, freq="M", name="Period")
y.name = "Number of shampoo sales"
return y
def load_longley(y_name="TOTEMP"):
"""Load the Longley dataset for forecasting with exogenous variables.
Parameters
----------
y_name: str, optional (default="TOTEMP")
Name of target variable (y)
Returns
-------
y: pd.Series
The target series to be predicted.
X: pd.DataFrame
The exogenous time series data for the problem.
Examples
--------
>>> from aeon.datasets import load_longley
>>> y, X = load_longley()
Notes
-----
This mulitvariate time series dataset contains various US macroeconomic
variables from 1947 to 1962 that are known to be highly collinear.
Dimensionality: multivariate, 6
Series length: 16
Frequency: Yearly
Number of cases: 1
Variable description:
TOTEMP - Total employment
GNPDEFL - Gross national product deflator
GNP - Gross national product
UNEMP - Number of unemployed
ARMED - Size of armed forces
POP - Population
References
----------
.. [1] Longley, J.W. (1967) "An Appraisal of Least Squares Programs for the
Electronic Computer from the Point of View of the User." Journal of
the American Statistical Association. 62.319, 819-41.
(https://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Longley.dat)
"""
name = "Longley"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
data = pd.read_csv(path, index_col=0)
data = data.set_index("YEAR")
data.index = pd.PeriodIndex(data.index, freq="Y", name="Period")
data = data.astype(float)
# Get target series
y = data.pop(y_name)
return y, data
def load_lynx():
"""Load the lynx univariate time series dataset for forecasting.
Returns
-------
y : pd.Series/DataFrame
Lynx sales dataset
Examples
--------
>>> from aeon.datasets import load_lynx
>>> y = load_lynx()
Notes
-----
The annual numbers of lynx trappings for 1821–1934 in Canada. This
time-series records the number of skins of
predators (lynx) that were collected over several years by the Hudson's
Bay Company. The dataset was
taken from Brockwell & Davis (1991) and appears to be the series
considered by Campbell & Walker (1977).
Dimensionality: univariate
Series length: 114
Frequency: Yearly
Number of cases: 1
This data shows aperiodic, cyclical patterns, as opposed to periodic,
seasonal patterns.
References
----------
.. [1] Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988). The New S
Language. Wadsworth & Brooks/Cole.
.. [2] Campbell, M. J. and Walker, A. M. (1977). A Survey of statistical
work on the Mackenzie River series of
annual Canadian lynx trappings for the years 1821–1934 and a new
analysis. Journal of the Royal Statistical Society
series A, 140, 411–431.
"""
name = "Lynx"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
y = pd.read_csv(path, index_col=0, dtype={1: float}).squeeze("columns")
y.index = pd.PeriodIndex(y.index, freq="Y", name="Period")
y.name = "Number of Lynx trappings"
return y
def load_airline():
"""Load the airline univariate time series dataset [1].
Returns
-------
y : pd.Series
Time series
Examples
--------
>>> from aeon.datasets import load_airline
>>> y = load_airline()
Notes
-----
The classic Box & Jenkins airline data. Monthly totals of international
airline passengers, 1949 to 1960.
Dimensionality: univariate
Series length: 144
Frequency: Monthly
Number of cases: 1
This data shows an increasing trend, non-constant (increasing) variance
and periodic, seasonal patterns.
References
----------
.. [1] Box, G. E. P., Jenkins, G. M. and Reinsel, G. C. (1976) Time Series
Analysis, Forecasting and Control. Third Edition. Holden-Day.
Series G.
"""
name = "Airline"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
y = pd.read_csv(path, index_col=0, dtype={1: float}).squeeze("columns")
# make sure time index is properly formatted
y.index = pd.PeriodIndex(y.index, freq="M", name="Period")
y.name = "Number of airline passengers"
return y
def load_uschange(y_name="Consumption"):
"""Load MTS dataset for forecasting Growth rates of personal consumption and income.
Returns
-------
y : pd.Series
selected column, default consumption
X : pd.DataFrame
columns with explanatory variables
Examples
--------
>>> from aeon.datasets import load_uschange
>>> y, X = load_uschange()
Notes
-----
Percentage changes in quarterly personal consumption expenditure,
personal disposable income, production, savings and the
unemployment rate for the US, 1960 to 2016.
Dimensionality: multivariate
Columns: ['Quarter', 'Consumption', 'Income', 'Production',
'Savings', 'Unemployment']
Series length: 188
Frequency: Quarterly
Number of cases: 1
This data shows an increasing trend, non-constant (increasing) variance
and periodic, seasonal patterns.
References
----------
.. [1] Data for "Forecasting: Principles and Practice" (2nd Edition)
"""
name = "Uschange"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
data = pd.read_csv(path, index_col=0).squeeze("columns")
# Sort by Quarter then set simple numeric index
# TODO add support for period/datetime indexing
# data.index = pd.PeriodIndex(data.index, freq='Y')
data = data.sort_values("Quarter")
data = data.reset_index(drop=True)
data.index = pd.Index(data.index, dtype=int)
data.name = name
y = data[y_name]
if y_name != "Quarter":
data = data.drop("Quarter", axis=1)
X = data.drop(y_name, axis=1)
return y, X
def load_gun_point_segmentation():
"""Load the GunPoint time series segmentation problem and returns X.
We group TS of the UCR GunPoint dataset by class label and concatenate
all TS to create segments with repeating temporal patterns and
characteristics. The location at which different classes were
concatenated are marked as change points.
We resample the resulting TS to control the TS resolution.
The window sizes for these datasets are hand-selected to capture
temporal patterns but are approximate and limited to the values
[10,20,50,100] to avoid over-fitting.
Returns
-------
X : pd.Series
Single time series for segmentation
period_length : int
The annotated period length by a human expert
change_points : numpy array
The change points annotated within the dataset
Examples
--------
>>> from aeon.datasets import load_gun_point_segmentation
>>> X, period_length, change_points = load_gun_point_segmentation()
"""
dir = "segmentation"
name = "GunPoint"
fname = name + ".csv"
period_length = int(10)
change_points = np.int32([900])
path = os.path.join(MODULE, DIRNAME, dir, fname)
ts = pd.read_csv(path, index_col=0, header=None).squeeze("columns")
return ts, period_length, change_points
def load_electric_devices_segmentation():
"""Load the Electric Devices segmentation problem and returns X.
We group TS of the UCR Electric Devices dataset by class label and concatenate
all TS to create segments with repeating temporal patterns and
characteristics. The location at which different classes were
concatenated are marked as change points.
We resample the resulting TS to control the TS resolution.
The window sizes for these datasets are hand-selected to capture
temporal patterns but are approximate and limited to the values
[10,20,50,100] to avoid over-fitting.
Returns
-------
X : pd.Series
Single time series for segmentation
period_length : int
The annotated period length by a human expert
change_points : numpy array
The change points annotated within the dataset
Examples
--------
>>> from aeon.datasets import load_electric_devices_segmentation
>>> X, period_length, change_points = load_electric_devices_segmentation()
"""
dir = "segmentation"
name = "ElectricDevices"
fname = name + ".csv"
period_length = int(10)
change_points = np.int32([1090, 4436, 5712, 7923])
path = os.path.join(MODULE, DIRNAME, dir, fname)
ts = pd.read_csv(path, index_col=0, header=None).squeeze("columns")
return ts, period_length, change_points
def load_PBS_dataset():
"""Load the Pharmaceutical Benefit Scheme univariate time series dataset [1]_.
Returns
-------
y : pd.Series
Time series
Examples
--------
>>> from aeon.datasets import load_PBS_dataset
>>> y = load_PBS_dataset()
Notes
-----
The Pharmaceutical Benefits Scheme (PBS) is the Australian government drugs
subsidy scheme.
Data comprises of the numbers of scripts sold each month for immune sera
and immunoglobulin products in Australia.
Dimensionality: univariate
Series length: 204
Frequency: Monthly
Number of cases: 1
The time series is intermittent, i.e contains small counts,
with many months registering no sales at all,
and only small numbers of items sold in other months.
References
----------
.. [1] Data for "Forecasting: Principles and Practice" (3rd Edition)
"""
name = "PBS_dataset"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
y = pd.read_csv(path, index_col=0, dtype={1: float}).squeeze("columns")
# make sure time index is properly formatted
y.index = pd.PeriodIndex(y.index, freq="M", name="Period")
y.name = "Number of scripts"
return y
def load_macroeconomic():
"""
Load the US Macroeconomic Data [1]_.
Returns
-------
y : pd.DataFrame
Time series
Examples
--------
>>> from aeon.datasets import load_macroeconomic
>>> y = load_macroeconomic() # doctest: +SKIP
Notes
-----
US Macroeconomic Data for 1959Q1 - 2009Q3.
Dimensionality: multivariate, 14
Series length: 203
Frequency: Quarterly
Number of cases: 1
This data is kindly wrapped via `statsmodels.datasets.macrodata`.
References
----------
.. [1] Wrapped via statsmodels:
https://www.statsmodels.org/dev/datasets/generated/macrodata.html
.. [2] Data Source: FRED, Federal Reserve Economic Data, Federal Reserve
Bank of St. Louis; http://research.stlouisfed.org/fred2/;
accessed December 15, 2009.
.. [3] Data Source: Bureau of Labor Statistics, U.S. Department of Labor;
http://www.bls.gov/data/; accessed December 15, 2009.
"""
_check_soft_dependencies("statsmodels")
import statsmodels.api as sm
y = sm.datasets.macrodata.load_pandas().data
y["year"] = y["year"].astype(int).astype(str)
y["quarter"] = y["quarter"].astype(int).astype(str).apply(lambda x: "Q" + x)
y["time"] = y["year"] + "-" + y["quarter"]
y.index = pd.PeriodIndex(data=y["time"], freq="Q", name="Period")
y = y.drop(columns=["year", "quarter", "time"])
y.name = "US Macroeconomic Data"
return y
def load_unit_test_tsf():
"""
Load tsf UnitTest dataset.
Returns
-------
loaded_data: pd.DataFrame
The converted dataframe containing the time series.
frequency: str
The frequency of the dataset.
forecast_horizon: int
The expected forecast horizon of the dataset.
contain_missing_values: bool
Whether the dataset contains missing values or not.
contain_equal_length: bool
Whether the series have equal lengths or not.
"""
path = os.path.join(MODULE, DIRNAME, "UnitTest", "UnitTest_Tsf_Loader.tsf")
data, meta = load_tsf_to_dataframe(path)
return (
data,
meta["frequency"],
meta["forecast_horizon"],
meta["contain_missing_values"],
meta["contain_equal_length"],
)
def load_solar(
start="2021-05-01",
end="2021-09-01",
normalise=True,
return_full_df=False,
api_version="v4",
):
"""Get national solar estimates for GB from Sheffield Solar PV_Live API.
This function calls the Sheffield Solar PV_Live API to extract national solar data
for the GB eletricity network. Note that these are estimates of the true solar
generation, since the true values are "behind the meter" and essentially
unknown.
The returned time series is half hourly. For more information please refer
to [1, 2]_.
Parameters
----------
start : string, default="2021-05-01"
The start date of the time-series in "YYYY-MM-DD" format
end : string, default="2021-09-01"
The end date of the time-series in "YYYY-MM-DD" format
normalise : boolean, default=True
Normalise the returned time-series by installed capacity?
return_full_df : boolean, default=False
Return a pd.DataFrame with power, capacity, and normalised estimates?
api_version : string or None, default="v4"
API version to call. If None then a stored sample of the data is loaded.
Return
------
pd.Series
References
----------
.. [1] https://www.solar.sheffield.ac.uk/pvlive/
.. [2] https://www.solar.sheffield.ac.uk/pvlive/api/
Examples
--------
>>> from aeon.datasets import load_solar # doctest: +SKIP
>>> y = load_solar() # doctest: +SKIP
"""
name = "solar"
fname = name + ".csv"
path = os.path.join(MODULE, DIRNAME, name, fname)
y = pd.read_csv(path, index_col=0, parse_dates=["datetime_gmt"], dtype={1: float})
y = y.asfreq("30T")
y = y.squeeze("columns")
if api_version is None:
return y
def _load_solar(
start="2021-05-01",
end="2021-09-01",
normalise=True,
return_full_df=False,
api_version="v4",
):
"""Private loader, for decoration with backoff."""
url = (
f"https://api0.solar.sheffield.ac.uk/pvlive/api/"
f"{api_version}/gsp/0?start={start}T00:00:00&end={end}"
f"extra_fields=capacity_mwp&data_format=csv"
)
df = (
pd.read_csv(
url, index_col=["gsp_id", "datetime_gmt"], parse_dates=["datetime_gmt"]
)