Simple Exponential Smoothing Model
Stepbystep guide on using the SimpleExponentialSmoothing Model
with Statsforecast
.
Table of Contents
 Introduction
 Simple Exponential Smoothing
 Loading libraries and data
 Explore data with the plot method
 Split the data into training and testing
 Implementation of SimpleExponentialSmoothing with StatsForecast
 Crossvalidation
 Model evaluation
 References
Introduction
Exponential smoothing was proposed in the late 1950s (Brown, 1959; Holt, 1957; Winters, 1960), and has motivated some of the most successful forecasting methods. Forecasts produced using exponential smoothing methods are weighted averages of past observations, with the weights decaying exponentially as the observations get older. In other words, the more recent the observation the higher the associated weight. This framework generates reliable forecasts quickly and for a wide range of time series, which is a great advantage and of major importance to applications in industry.
The simple exponential smoothing model is a method used in time series analysis to predict future values based on historical observations. This model is based on the idea that future values of a time series will be influenced by past values, and that the influence of past values will decrease exponentially as you go back in time.
The simple exponential smoothing model uses a smoothing factor, which is a number between 0 and 1 that indicates the relative importance given to past observations in predicting future values. A value of 1 indicates that all past observations are given equal importance, while a value of 0 indicates that only the latest observation is considered.
The simple exponential smoothing model can be expressed mathematically as:
$\hat{y}_{T+1T} = \alpha y_T + \alpha(1\alpha) y_{T1} + \alpha(1\alpha)^2 y_{T2}+ \cdots,$
where $y_T$ is the observed value in period $t$, $\hat{y}_{T+1T}$ is the predicted value for the next period, y $(t1)$ is the observed value in the previous period, and $\alpha$ is the smoothing factor.
The simple exponential smoothing model is a widely used forecasting model due to its simplicity and ease of use. However, it also has its limitations, as it cannot capture complex patterns in the data and is not suitable for time series with trends or seasonal patterns.
Building of Simple exponential smoothing model
The simplest of the exponentially smoothing methods is naturally called simple exponential smoothing (SES). This method is suitable for forecasting data with no clear trend or seasonal pattern.
Using the naïve method, all forecasts for the future are equal to the last observed value of the series, $\hat{y}_{T+hT} = y_{T},$
for $h=1,2,\dots$. Hence, the naïve method assumes that the most recent observation is the only important one, and all previous observations provide no information for the future. This can be thought of as a weighted average where all of the weight is given to the last observation.
Using the average method, all future forecasts are equal to a simple average of the observed data, $\hat{y}_{T+hT} = \frac1T \sum_{t=1}^T y_t,$
for $h=1,2,\dots$ Hence, the average method assumes that all observations are of equal importance, and gives them equal weights when generating forecasts.
We often want something between these two extremes. For example, it may be sensible to attach larger weights to more recent observations than to observations from the distant past. This is exactly the concept behind simple exponential smoothing. Forecasts are calculated using weighted averages, where the weights decrease exponentially as observations come from further in the past — the smallest weights are associated with the oldest observations:
where $0 \le \alpha \le 1$ is the smoothing parameter. The onestepahead forecast for time $T+1$ is a weighted average of all of the observations in the series $y_1,\dots,y_T$. The rate at which the weights decrease is controlled by the parameter $\alpha$.
For any $\alpha$ between 0 and 1, the weights attached to the observations decrease exponentially as we go back in time, hence the name “exponential smoothing”. If $\alpha$ is small (i.e., close to 0), more weight is given to observations from the more distant past. If $\alpha$ is large (i.e., close to 1), more weight is given to the more recent observations. For the extreme case where $\alpha=1$, $\hat{y}_{T+1T}=y_T$ and the forecasts are equal to the naïve forecasts.
We present two equivalent forms of simple exponential smoothing, each of which leads to the forecast Equation (1).
Weighted average form
The forecast at time $T+1$ is equal to a weighted average between the most recent observation $y_T$ and the previous forecast $\hat{y}_{TT1}$:
$\hat{y}_{T+1T} = \alpha y_T + (1\alpha) \hat{y}_{TT1},$
where $0 \le \alpha \le 1$ is the smoothing parameter. Similarly, we can write the fitted values as $\hat{y}_{t+1t} = \alpha y_t + (1\alpha) \hat{y}_{tt1},$
for $t=1,\dots,T$. (Recall that fitted values are simply onestep forecasts of the training data.)
The process has to start somewhere, so we let the first fitted value at time 1 be denoted by $\ell_{0}$ (which we will have to estimate). Then
Substituting each equation into the following equation, we obtain
The last term becomes tiny for large $T$. So, the weighted average form leads to the same forecast Equation (1).
Component form
An alternative representation is the component form. For simple exponential smoothing, the only component included is the level, $\ell_{t}$. Component form representations of exponential smoothing methods comprise a forecast equation and a smoothing equation for each of the components included in the method. The component form of simple exponential smoothing is given by:
where $\ell_{t}$ is the level (or the smoothed value) of the series at time $t$. Setting $h=1$ gives the fitted values, while setting $t=T$ gives the true forecasts beyond the training data.
The forecast equation shows that the forecast value at time $t+1$ is the estimated level at time $t$. The smoothing equation for the level (usually referred to as the level equation) gives the estimated level of the series at each period $t$.
If we replace $\ell_{t}$ with $\hat{y}_{t+1t}$ and $\ell_{t1}$ with $\hat{y}_{tt1}$ in the smoothing equation, we will recover the weighted average form of simple exponential smoothing.
The component form of simple exponential smoothing is not particularly useful on its own, but it will be the easiest form to use when we start adding other components.
Flat forecasts
Simple exponential smoothing has a “flat” forecast function:
$\hat{y}_{T+hT} = \hat{y}_{T+1T}=\ell_T, \qquad h=2,3,\dots.$
That is, all forecasts take the same value, equal to the last level component. Remember that these forecasts will only be suitable if the time series has no trend or seasonal component.
Loading libraries and data
Tip
Statsforecast will be needed. To install, see instructions.
Next, we import plotting libraries and configure the plotting style.
Time  Ads  

0  20170913T00:00:00  80115 
1  20170913T01:00:00  79885 
2  20170913T02:00:00  89325 
3  20170913T03:00:00  101930 
4  20170913T04:00:00  121630 
The input to StatsForecast is always a data frame in long format with three columns: unique_id, ds and y:

The
unique_id
(string, int or category) represents an identifier for the series. 
The
ds
(datestamp) column should be of a format expected by Pandas, ideally YYYYMMDD for a date or YYYYMMDD HH:MM:SS for a timestamp. 
The
y
(numeric) represents the measurement we wish to forecast.
ds  y  unique_id  

0  20170913T00:00:00  80115  1 
1  20170913T01:00:00  79885  1 
2  20170913T02:00:00  89325  1 
…  …  …  … 
213  20170921T21:00:00  103080  1 
214  20170921T22:00:00  95155  1 
215  20170921T23:00:00  80285  1 
Explore Data with the plot method
Plot some series using the plot method from the StatsForecast class. This method prints a random series from the dataset and is useful for basic EDA.
Autocorrelation plots
Split the data into training and testing
Let’s divide our data into sets
 Data to train our
Simple Exponential Smoothing (SES)
.  Data to test our model
For the test data we will use the last 30 hours to test and evaluate the performance of our model.
Now let’s plot the training data and the test data.
Implementation of SimpleExponentialSmoothing with StatsForecast
To also know more about the parameters of the functions of the
SimpleExponentialSmoothing Model
, they are listed below. For more
information, visit the
documentation.
Load libraries
Instantiating Model
We are going to build different models, for different values of alpha.
We fit the models by instantiating a new StatsForecast object with the following parameters:
models: a list of models. Select the models you want from models and import them.

freq:
a string indicating the frequency of the data. (See panda’s available frequencies.) 
n_jobs:
n_jobs: int, number of jobs used in the parallel processing, use 1 for all cores. 
fallback_model:
a model to be used if a model fails.
Any settings are passed into the constructor. Then you call its fit method and pass in the historical data frame.
Fit the Model
Let’s see the results of our Simple
Simple Exponential Smoothing model (SES)
. We can observe it with the
following instruction:
As we can see, the result obtained above has an output in a dictionary,
to extract each element from the dictionary we are going to use the
.get()
function to extract the element and then we are going to save
it in a pd.DataFrame()
.
fitted01  fitted05  fitted08  ds  

0  NaN  NaN  NaN  20170913 00:00:00 
1  80115.000000  80115.000000  80115.000000  20170913 01:00:00 
2  80092.000000  80000.000000  79931.000000  20170913 02:00:00 
…  …  …  …  … 
213  131581.593750  138842.562500  129852.359375  20170921 21:00:00 
214  128731.429688  120961.281250  108434.468750  20170921 22:00:00 
215  125373.789062  108058.140625  97810.890625  20170921 23:00:00 
Forecast Method
If you want to gain speed in productive settings where you have multiple
series or models we recommend using the
StatsForecast.forecast
method instead of .fit
and .predict
.
The main difference is that the .forecast
doest not store the fitted
values and is highly scalable in distributed environments.
The forecast method takes two arguments: forecasts next h
(horizon)
and level
.
h (int):
represents the forecast h steps into the future. In this case, 30 hours ahead.
The forecast object here is a new data frame that includes a column with the name of the model and the y hat values, as well as columns for the uncertainty intervals. Depending on your computer, this step should take around 1min.
ds  SES01  SES05  SES08  

unique_id  
1  20170922 00:00:00  120864.90625  94171.570312  83790.179688 
1  20170922 01:00:00  120864.90625  94171.570312  83790.179688 
1  20170922 02:00:00  120864.90625  94171.570312  83790.179688 
1  20170922 03:00:00  120864.90625  94171.570312  83790.179688 
1  20170922 04:00:00  120864.90625  94171.570312  83790.179688 
ds  y  SES01  SES05  SES08  

unique_id  
1  20170913 00:00:00  80115.0  NaN  NaN  NaN 
1  20170913 01:00:00  79885.0  80115.000000  80115.00  80115.000000 
1  20170913 02:00:00  89325.0  80092.000000  80000.00  79931.000000 
1  20170913 03:00:00  101930.0  81015.296875  84662.50  87446.203125 
1  20170913 04:00:00  121630.0  83106.773438  93296.25  99033.242188 
unique_id  ds  SES01  SES05  SES08  

0  1  20170922 00:00:00  120864.90625  94171.570312  83790.179688 
1  1  20170922 01:00:00  120864.90625  94171.570312  83790.179688 
2  1  20170922 02:00:00  120864.90625  94171.570312  83790.179688 
3  1  20170922 03:00:00  120864.90625  94171.570312  83790.179688 
4  1  20170922 04:00:00  120864.90625  94171.570312  83790.179688 
Predict method
To generate forecasts use the predict method.
The predict method takes two arguments: forecasts the next h
(for
horizon). * h (int):
represents the forecast $h$ steps into the
future. In this case, 30 hours ahead.
The forecast object here is a new data frame that includes a column with
the name of the model and the y hat
values, as well as columns for the
uncertainty intervals.
This step should take less than 1 second.
ds  SES01  SES05  SES08  

unique_id  
1  20170922 00:00:00  120864.90625  94171.570312  83790.179688 
1  20170922 01:00:00  120864.90625  94171.570312  83790.179688 
1  20170922 02:00:00  120864.90625  94171.570312  83790.179688 
…  …  …  …  … 
1  20170923 03:00:00  120864.90625  94171.570312  83790.179688 
1  20170923 04:00:00  120864.90625  94171.570312  83790.179688 
1  20170923 05:00:00  120864.90625  94171.570312  83790.179688 
We can join the forecast result with the historical data using the
pandas function pd.concat()
, and then be able to use this result for
graphing.
y  unique_id  SES01  SES05  SES08  

ds  
20170913 00:00:00  80115.0  1  NaN  NaN  NaN 
20170913 01:00:00  79885.0  1  NaN  NaN  NaN 
20170913 02:00:00  89325.0  1  NaN  NaN  NaN 
…  …  …  …  …  … 
20170923 03:00:00  NaN  NaN  120864.90625  94171.570312  83790.179688 
20170923 04:00:00  NaN  NaN  120864.90625  94171.570312  83790.179688 
20170923 05:00:00  NaN  NaN  120864.90625  94171.570312  83790.179688 
Let’s plot the same graph using the plot function that comes in
Statsforecast
, as shown below.
Crossvalidation
In previous steps, we’ve taken our historical data to predict the future. However, to asses its accuracy we would also like to know how the model would have performed in the past. To assess the accuracy and robustness of your models on your data perform CrossValidation.
With time series data, Cross Validation is done by defining a sliding window across the historical data and predicting the period following it. This form of crossvalidation allows us to arrive at a better estimation of our model’s predictive abilities across a wider range of temporal instances while also keeping the data in the training set contiguous as is required by our models.
The following graph depicts such a Cross Validation Strategy:
Perform time series crossvalidation
Crossvalidation of time series models is considered a best practice but most implementations are very slow. The statsforecast library implements crossvalidation as a distributed operation, making the process less timeconsuming to perform. If you have big datasets you can also perform Cross Validation in a distributed cluster using Ray, Dask or Spark.
In this case, we want to evaluate the performance of each model for the
last 30 hourly (n_windows=)
, forecasting every second months
(step_size=30)
. Depending on your computer, this step should take
around 1 min.
The cross_validation method from the StatsForecast class takes the following arguments.

df:
training data frame 
h (int):
represents h steps into the future that are being forecasted. In this case, 30 hours ahead. 
step_size (int):
step size between each window. In other words: how often do you want to run the forecasting processes. 
n_windows(int):
number of windows used for cross validation. In other words: what number of forecasting processes in the past do you want to evaluate.
The crossvaldation_df object is a new data frame that includes the following columns:
unique_id:
index. If you dont like working with index just runcrossvalidation_df.resetindex()
.ds:
datestamp or temporal indexcutoff:
the last datestamp or temporal index for then_windows
.y:
true valuemodel:
columns with the model’s name and fitted value.
ds  cutoff  y  SES01  SES05  SES08  

unique_id  
1  20170918 06:00:00  20170918 05:00:00  99440.0  118499.953125  109816.250  112747.695312 
1  20170918 07:00:00  20170918 05:00:00  97655.0  118499.953125  109816.250  112747.695312 
1  20170918 08:00:00  20170918 05:00:00  97655.0  118499.953125  109816.250  112747.695312 
…  …  …  …  …  …  … 
1  20170921 21:00:00  20170920 17:00:00  103080.0  126112.898438  140008.125  139770.906250 
1  20170921 22:00:00  20170920 17:00:00  95155.0  126112.898438  140008.125  139770.906250 
1  20170921 23:00:00  20170920 17:00:00  80285.0  126112.898438  140008.125  139770.906250 
Evaluate Model
We can now compute the accuracy of the forecast using an appropiate
accuracy metric. Here we’ll use the Root Mean Squared Error (RMSE). To
do this, we first need to install datasetsforecast
, a Python library
developed by Nixtla that includes a function to compute the RMSE.
The function to compute the RMSE takes two arguments:
 The actual values.
 The forecasts, in this case,
Simple Exponential Smoothing Model (SES)
.
SES01  SES05  SES08  best_model  

unique_id  
1  27676.533203  29132.158203  29308.0  SES01 
Acknowledgements
We would like to thank Naren Castellon for writing this tutorial.
References
 Changquan Huang • Alla Petukhina. Springer series (2022). Applied Time Series Analysis and Forecasting with Python.
 James D. Hamilton. Time Series Analysis Princeton University Press, Princeton, New Jersey, 1st Edition, 1994.
 Nixtla Parameters.
 Pandas available frequencies.
 Rob J. Hyndman and George Athanasopoulos (2018). “Forecasting principles and practice, Time series crossvalidation”..
 Seasonal periods Rob J Hyndman.