2
2
3
3
An implementation of the exponential smoothing statistics forecasting algorithm.
4
4
Implements additive and multiplicative error models,
5
- None, additive and multiplicative (including damped) trend and
6
- None, additive and multiplicative seasonality
5
+ `` None`` , additive, and multiplicative (including damped) trend, and
6
+ `` None`` , additive, and multiplicative seasonality.
7
7
"""
8
8
9
+
9
10
__maintainer__ = []
10
11
__all__ = ["ETSForecaster" , "NONE" , "ADDITIVE" , "MULTIPLICATIVE" ]
11
12
@@ -26,30 +27,30 @@ class ETSForecaster(BaseForecaster):
26
27
"""Exponential Smoothing forecaster.
27
28
28
29
An implementation of the exponential smoothing forecasting algorithm.
29
- Implements additive and multiplicative error models, None, additive and
30
- multiplicative (including damped) trend and None, additive and mutliplicative
30
+ Implements additive and multiplicative error models, `` None`` , additive, and
31
+ multiplicative (including damped) trend, and `` None`` , additive, and multiplicative
31
32
seasonality. See [1]_ for a description.
32
33
33
34
Parameters
34
35
----------
35
36
error_type : int, default = 1
36
- Either NONE (0), ADDITIVE (1) or MULTIPLICATIVE (2).
37
+ Either `` NONE`` (0), `` ADDITIVE`` (1) or `` MULTIPLICATIVE`` (2).
37
38
trend_type : int, default = 0
38
- Either NONE (0), ADDITIVE (1) or MULTIPLICATIVE (2).
39
+ Either `` NONE`` (0), `` ADDITIVE`` (1) or `` MULTIPLICATIVE`` (2).
39
40
seasonality_type : int, default = 0
40
- Either NONE (0), ADDITIVE (1) or MULTIPLICATIVE (2).
41
+ Either `` NONE`` (0), `` ADDITIVE`` (1) or `` MULTIPLICATIVE`` (2).
41
42
seasonal_period : int, default=1
42
- Length of seasonality period. If seasonality_type is NONE, this is assumed to
43
- be 1
43
+ Length of seasonality period. If `` seasonality_type`` is `` NONE`` , this is assumed to
44
+ be ``1``.
44
45
alpha : float, default = 0.1
45
46
Level smoothing parameter.
46
47
beta : float, default = 0.01
47
- Trend smoothing parameter. If trend_type is NONE, this is assumed to be 0.0.
48
+ Trend smoothing parameter. If `` trend_type`` is `` NONE`` , this is assumed to be `` 0.0`` .
48
49
gamma : float, default = 0.01
49
- Seasonal smoothing parameter. If seasonality is NONE, this is assumed to be
50
- 0.0.
50
+ Seasonal smoothing parameter. If `` seasonality`` is `` NONE`` , this is assumed to be
51
+ `` 0.0`` .
51
52
phi : float, default = 0.99
52
- Trend damping smoothing parameters
53
+ Trend damping smoothing parameter.
53
54
horizon : int, default = 1
54
55
The horizon to forecast to.
55
56
@@ -79,7 +80,8 @@ class ETSForecaster(BaseForecaster):
79
80
ETSForecaster(alpha=0.4, beta=0.2, gamma=0.5, phi=0.8)
80
81
>>> forecaster.predict()
81
82
449.9435566831507
82
- """
83
+ """
84
+
83
85
84
86
def __init__ (
85
87
self ,
@@ -108,22 +110,23 @@ def __init__(
108
110
super ().__init__ (horizon = horizon , axis = 1 )
109
111
110
112
def _fit (self , y , exog = None ):
111
- """Fit Exponential Smoothing forecaster to series y .
113
+ """Fit Exponential Smoothing forecaster to series ``y`` .
112
114
113
- Fit a forecaster to predict self.horizon steps ahead using y .
115
+ Fit a forecaster to predict `` self.horizon`` steps ahead using ``y`` .
114
116
115
117
Parameters
116
118
----------
117
- y : np.ndarray
118
- A time series on which to learn a forecaster to predict horizon ahead
119
- exog : np.ndarray, default =None
120
- Optional exogenous time series data assumed to be aligned with y
119
+ y : `` np.ndarray``
120
+ A time series on which to learn a forecaster to predict `` horizon`` ahead.
121
+ exog : `` np.ndarray`` , default = `` None``
122
+ Optional exogenous time series data assumed to be aligned with ``y``.
121
123
122
124
Returns
123
125
-------
124
126
self
125
- Fitted BaseForecaster.
127
+ Fitted `` BaseForecaster`` .
126
128
"""
129
+
127
130
self .n_timepoints_ = len (y )
128
131
if self .error_type != MULTIPLICATIVE and self .error_type != ADDITIVE :
129
132
raise ValueError ("Error must be either additive or multiplicative" )
@@ -159,21 +162,22 @@ def _fit(self, y, exog=None):
159
162
160
163
def _predict (self , y = None , exog = None ):
161
164
"""
162
- Predict the next horizon steps ahead.
165
+ Predict the next `` horizon`` steps ahead.
163
166
164
167
Parameters
165
168
----------
166
- y : np.ndarray, default = None
167
- A time series to predict the next horizon value for. If None,
168
- predict the next horizon value after series seen in fit.
169
- exog : np.ndarray, default = None
170
- Optional exogenous time series data assumed to be aligned with y
169
+ y : `` np.ndarray`` , default = `` None``
170
+ A time series to predict the next `` horizon`` value for. If `` None`` ,
171
+ predict the next `` horizon`` value after series seen in `` fit`` .
172
+ exog : `` np.ndarray`` , default = `` None``
173
+ Optional exogenous time series data assumed to be aligned with ``y``.
171
174
172
175
Returns
173
176
-------
174
177
float
175
- single prediction self.horizon steps ahead of y .
178
+ Single prediction `` self.horizon`` steps ahead of ``y`` .
176
179
"""
180
+
177
181
return _predict_numba (
178
182
self .trend_type ,
179
183
self .seasonality_type ,
@@ -266,14 +270,22 @@ def _predict_numba(
266
270
@njit (nogil = NOGIL , cache = CACHE )
267
271
def _initialise (trend_type , seasonality_type , seasonal_period , data ):
268
272
"""
269
- Initialize level, trend, and seasonality values for the ETS model.
273
+ Predict the next ``horizon`` steps ahead.
274
+
275
+ Parameters
276
+ ----------
277
+ y : ``np.ndarray``, default = ``None``
278
+ A time series to predict the next ``horizon`` value for. If ``None``,
279
+ predict the next ``horizon`` value after series seen in ``fit``.
280
+ exog : ``np.ndarray``, default = ``None``
281
+ Optional exogenous time series data assumed to be aligned with ``y``.
282
+
283
+ Returns
284
+ -------
285
+ float
286
+ Single prediction ``self.horizon`` steps ahead of ``y``.
287
+ """
270
288
271
- Parameters
272
- ----------
273
- data : array-like
274
- The time series data
275
- (should contain at least two full seasons if seasonality is specified)
276
- """
277
289
# Initial Level: Mean of the first season
278
290
level = np .mean (data [:seasonal_period ])
279
291
# Initial Trend
@@ -326,11 +338,12 @@ def _update_states(
326
338
327
339
Parameters
328
340
----------
329
- data_item: float
341
+ data_item : `` float``
330
342
The current value of the time series.
331
- seasonal_index: int
343
+ seasonal_index : `` int``
332
344
The index to update the seasonal component.
333
345
"""
346
+
334
347
# Retrieve the current state values
335
348
curr_level = level
336
349
curr_seasonality = seasonality
@@ -376,29 +389,29 @@ def _update_states(
376
389
@njit (nogil = NOGIL , cache = CACHE )
377
390
def _predict_value (trend_type , seasonality_type , level , trend , seasonality , phi ):
378
391
"""
379
-
380
392
Generate various useful values, including the next fitted value.
381
393
382
394
Parameters
383
395
----------
384
- trend : float
385
- The current trend value for the model
386
- level : float
387
- The current level value for the model
388
- seasonality : float
389
- The current seasonality value for the model
390
- phi : float
391
- The damping parameter for the model
396
+ trend : `` float``
397
+ The current trend value for the model.
398
+ level : `` float``
399
+ The current level value for the model.
400
+ seasonality : `` float``
401
+ The current seasonality value for the model.
402
+ phi : `` float``
403
+ The damping parameter for the model.
392
404
393
405
Returns
394
406
-------
395
- fitted_value : float
396
- single prediction based on the current state variables.
397
- damped_trend : float
398
- The damping parameter combined with the trend dependant on the model type
399
- trend_level_combination : float
407
+ fitted_value : `` float``
408
+ Single prediction based on the current state variables.
409
+ damped_trend : `` float``
410
+ The damping parameter combined with the trend, dependent on the model type.
411
+ trend_level_combination : `` float``
400
412
Combination of the trend and level based on the model type.
401
413
"""
414
+
402
415
# Apply damping parameter and
403
416
# calculate commonly used combination of trend and level components
404
417
if trend_type == MULTIPLICATIVE :
@@ -413,4 +426,4 @@ def _predict_value(trend_type, seasonality_type, level, trend, seasonality, phi)
413
426
fitted_value = trend_level_combination * seasonality
414
427
else : # Additive seasonality, if no seasonality, then seasonality = 0
415
428
fitted_value = trend_level_combination + seasonality
416
- return fitted_value , damped_trend , trend_level_combination
429
+ return fitted_value , damped_trend , trend_level_combination
0 commit comments