You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multivariate time series forecasting is natively supported for all the forecasting methods available.
46
+
**GLOBAL and MULTIVARIATE time series forecasting are natively supported for all the forecasting methods available.** For GLOBAL forecasting, use the `groups` parameter to specify the column of the input data that contains the group identifiers. For MULTIVARIATE forecasting, pass a target with multiple columns when calling fit.
47
47
48
48
## Installation
49
49
```shell
50
50
pip install --upgrade tspiral
51
51
```
52
-
The module depends only on NumPy and Scikit-Learn (>=0.24.2). Python 3.6 or above is supported.
52
+
The module depends only on NumPy, Pandas, and Scikit-Learn (>=0.24.2). Python 3.6 or above is supported.
53
53
54
54
## Media
55
55
@@ -68,15 +68,17 @@ from sklearn.linear_model import Ridge
68
68
from tspiral.forecasting import ForecastingCascade
69
69
timesteps =400
70
70
e = np.random.normal(0,1, (timesteps,))
71
-
y =2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
71
+
y = np.concatenate([
72
+
2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,
73
+
2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,
74
+
])
75
+
X = [[0]]*timesteps+[[1]]*timesteps
72
76
model = ForecastingCascade(
73
77
Ridge(),
74
78
lags=range(1,24+1),
75
-
use_exog=False,
76
-
accept_nan=False
77
-
)
78
-
model.fit(None, y)
79
-
forecasts = model.predict(np.arange(24*3))
79
+
groups=[0],
80
+
).fit(X, y)
81
+
forecasts = model.predict([[0]]*80+[[1]]*80)
80
82
```
81
83
82
84
-**Direct Forecasting**
@@ -86,16 +88,18 @@ from sklearn.linear_model import Ridge
86
88
from tspiral.forecasting import ForecastingChain
87
89
timesteps =400
88
90
e = np.random.normal(0,1, (timesteps,))
89
-
y =2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
91
+
y = np.concatenate([
92
+
2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,
93
+
2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,
94
+
])
95
+
X = [[0]]*timesteps+[[1]]*timesteps
90
96
model = ForecastingChain(
91
97
Ridge(),
92
98
n_estimators=24,
93
99
lags=range(1,24+1),
94
-
use_exog=False,
95
-
accept_nan=False
96
-
)
97
-
model.fit(None, y)
98
-
forecasts = model.predict(np.arange(24*3))
100
+
groups=[0],
101
+
).fit(X, y)
102
+
forecasts = model.predict([[0]]*80+[[1]]*80)
99
103
```
100
104
101
105
-**Stacking Forecasting**
@@ -106,15 +110,18 @@ from sklearn.tree import DecisionTreeRegressor
106
110
from tspiral.forecasting import ForecastingStacked
107
111
timesteps =400
108
112
e = np.random.normal(0,1, (timesteps,))
109
-
y =2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
113
+
y = np.concatenate([
114
+
2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,
115
+
2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,
116
+
])
117
+
X = [[0]]*timesteps+[[1]]*timesteps
110
118
model = ForecastingStacked(
111
119
[Ridge(), DecisionTreeRegressor()],
112
120
test_size=24*3,
113
121
lags=range(1,24+1),
114
-
use_exog=False
115
-
)
116
-
model.fit(None, y)
117
-
forecasts = model.predict(np.arange(24*3))
122
+
groups=[0],
123
+
).fit(X, y)
124
+
forecasts = model.predict([[0]]*80+[[1]]*80)
118
125
```
119
126
120
127
-**Rectified Forecasting**
@@ -125,16 +132,19 @@ from sklearn.tree import DecisionTreeRegressor
125
132
from tspiral.forecasting import ForecastingRectified
126
133
timesteps =400
127
134
e = np.random.normal(0,1, (timesteps,))
128
-
y =2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e
135
+
y = np.concatenate([
136
+
2*np.sin(np.arange(timesteps)*(2*np.pi/24))+e,
137
+
2*np.cos(np.arange(timesteps)*(2*np.pi/24))+e,
138
+
])
139
+
X = [[0]]*timesteps+[[1]]*timesteps
129
140
model = ForecastingRectified(
130
141
[Ridge(), DecisionTreeRegressor()],
131
-
n_estimators=200,
142
+
n_estimators=24*3,
132
143
test_size=24*3,
133
144
lags=range(1,24+1),
134
-
use_exog=False
135
-
)
136
-
model.fit(None, y)
137
-
forecasts = model.predict(np.arange(24*3))
145
+
groups=[0],
146
+
).fit(X, y)
147
+
forecasts = model.predict([[0]]*80+[[1]]*80)
138
148
```
139
149
140
150
More examples in the [notebooks folder](https://github.com/cerlymarco/tspiral/tree/main/notebooks).
0 commit comments