-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
test_time_series_indices.py
108 lines (88 loc) · 3.04 KB
/
test_time_series_indices.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
import os
import pandas as pd
from pycaret.datasets import get_data
from pycaret.time_series import TSForecastingExperiment
os.environ["PYCARET_TESTING"] = "1"
def create_models(exp: TSForecastingExperiment, prophet: bool = True):
"""Function to create a few trial models that support both univariate and
multivariate forecasting.
Parameters
----------
exp : TSForecastingExperiment
The Time Series experiment object
prophet : bool, optional
Should Prophet model be created, by default True
"""
model = exp.create_model("arima")
exp.predict_model(model)
exp.plot_model(model)
if "prophet" in exp.models().index:
model = exp.create_model("prophet")
exp.predict_model(model)
exp.plot_model(model)
def test_time_series_indices():
"""Checks working with various types of indices with both univariate and multivariate datasets"""
####################
#### Univariate ####
####################
#### With Period Index ----
exp = TSForecastingExperiment()
data = get_data("airline")
exp.setup(data=data, fh=12, fold=2, session_id=42)
create_models(exp)
#### With Datetime Index ----
exp = TSForecastingExperiment()
data = get_data("airline")
data = data.to_timestamp()
exp.setup(data=data, fh=12, fold=2, session_id=42)
create_models(exp)
#### With Int Index ----
exp = TSForecastingExperiment()
data = get_data("airline")
data.reset_index(drop=True, inplace=True)
exp.setup(data=data, fh=12, fold=2, seasonal_period=12, session_id=42)
create_models(exp)
#######################
#### Multivariate ####
#######################
# TODO: Find a better source of data ----
data = pd.read_csv(
"https://raw.githubusercontent.com/ngupta23/DS6373_TimeSeries/2b40f0071c3b7ec6a05dc0106f64e041f8cbaaef/Projects/gdp_prediction/data/economic_indicators_all_ex_3mo_china_inc_treas3mo.csv"
)
data["date"] = pd.to_datetime(data["date"].str.replace("\s", "-"))
#### With Datetime Index Column ----
exp = TSForecastingExperiment()
exp.setup(
data=data,
target="gdp_change",
index="date",
fh=2,
fold=2,
session_id=42,
)
create_models(exp)
#### With Datetime Index ----
data_temp = data.copy()
data_temp.set_index("date", inplace=True)
exp = TSForecastingExperiment()
exp.setup(data=data_temp, target="gdp_change", fh=2, fold=2, session_id=42)
create_models(exp)
#### With Period Index ----
data_temp = data.copy()
data_temp.set_index("date", inplace=True)
data_temp.index = data_temp.index.to_period()
exp = TSForecastingExperiment()
exp.setup(data=data_temp, target="gdp_change", fh=2, fold=2, session_id=42)
create_models(exp)
#### With Int Index ----
exp = TSForecastingExperiment()
exp.setup(
data=data,
target="gdp_change",
ignore_features=["date"],
seasonal_period=4,
fh=2,
fold=2,
session_id=42,
)
create_models(exp)