Snehal_bm — Published On August 3, 2021 and Last Modified On April 26th, 2023

Time series analysis is a popular field of data science and machine learning that decomposes historical data to identify trends, seasonality, and noise to forecast future trends. Time series forecasting algorithms range from simple techniques like moving averages and exponential smoothing to deep learning methods like recurrent neural networks and XG Boost. Hybrid forecasting techniques that combine multiple approaches are also commonly used to improve accuracy. Independent variables, such as discount percentages or temperature, can influence predictions. The choice of algorithm depends on the data set and the business problem at hand. Time series analysis is critical for making informed decisions based on historical data.

This article was published as a part of the Data Science Blogathon

## What is Holt Winter’s Method?

Holt-Winters is a model of time series behavior. Forecasting always requires a model, and Holt-Winters is a way to model three aspects of the time series:

• A typical value (average)
• A slope (trend) over time
• A cyclical repeating pattern (seasonality)

Real-world data like that of demand data in any industry generally has a lot of seasonality and trends. When forecasting demands in such cases requires models which will account for the trend and seasonality in the data as the decision made by the business is going to be based on the result of this model. For such cases, Holt winter’s method is one of the many time series prediction methods which can be used for forecasting.

## Holt-Winters Triple Exponential Smoothing Formula Explained

Holt-Winter’s Exponential Smoothing as named after its two contributors: Charles Holt and Peter Winter’s is one of the oldest time series analysis techniques which takes into account the trend and seasonality while doing the forecasting. This method has 3 major aspects for performing the predictions. It has an average value with the trend and seasonality. The three aspects are 3 types of exponential smoothing and hence the hold winter’s method is also known as triple exponential smoothing.

Let us look at each of the aspects in detail.

• Exponential Smoothing: Simple exponential smoothing as the name suggest is used for forecasting when the data set has no trends or seasonality.
• Holt’s Smoothing method: Holt’s smoothing technique, also known as linear exponential smoothing, is a widely known smoothing model for forecasting data that has a trend.
• Winter’s Smoothing method: Winter’s smoothing technique allows us to include seasonality while making the prediction along with the trend.

Hence the Holt winter’s method takes into account average along with trend and seasonality while making the time series prediction.

Forecast equation^yt+h|t=ℓt+hbt

Level equationℓt=αyt+(1−α)(ℓt−1+bt−1)

Trend equationbt=β∗(ℓt−ℓt−1)+(1−β∗)bt−1

Where ℓtℓt is an estimate of the level of the series at time tt,

btbt is an estimate of the trend of the series at time tt,

αα is the smoothing coefficient

Also Read: This is How Experts Predict the Future of AI

## Example with Code

Let us look at Holt-Winter’s time series analysis with an example. We have the number of visitors on a certain website for few days, let us try to predict the number of visitors for the next 3 days using the Holt-Winter’s method. Below is the code in python

The first step to any model building is exploratory data analysis or EDA, lets look at the data and try to clean it before fitting a model onto it.

## Missing Values Treatment

```#counting the number of missing data points
Visitors_df_missing = (visitors.[ 'no_of_visits']=nan).sum()
```#Replace the missing values with the mean value
visitors ['no_of_visits'].fillna(value= visitors ['no_of_visits'].mean(), inplace=True)```

## Outlier Detection and Treatment

```import seaborn as sns
sns.boxplot(x= visitors ['no_of_visits'])```
`#calculating the z score`
`visitors [‘z_score’] = visitors. 'no_of_visits' - visitors. 'no_of_visits'.mean())/visitors. 'no_of_visits'.std(ddof=0)`
```#exclude the rowl with z score more than 3
visitors [(np.abs(stats.zscore(visitors [‘z_score’])) < 3)]```
```#re-sampling the data to monthly buckets
visitors.set_index('date', inplace=True)
visitors.resample('MS').sum()```

Now our EDA is completed and the data set is ready for modelling

`# Lets import all the required libraries`
```import pandas as pd
from matplotlib import pyplot as plt
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.holtwinters import SimpleExpSmoothing
from statsmodels.tsa.holtwinters import ExponentialSmoothing```
```# Input the visitors data using pandas
print(visitors.shape)
print(visitors.head()) # print the data frame
visitors[['no_of_visits']].plot(title='visitors Data')```

`visitors.sort_index(inplace=True) # sort the data as per the index`
```# Decompose the data frame to get the trend, seasonality and noise
decompose_result = seasonal_decompose(visitors['no_of_visits'],model='multiplicative',period=1)
decompose_result.plot()
plt.show()```
```# Set the value of Alpha and define x as the time period
x = 12
alpha = 1/(2*x)```
```# Single exponential smoothing of the visitors data set
visitors['HWES1'] = SimpleExpSmoothing(visitors['no_of_visits']).fit(smoothing_level=alpha,optimized=False,use_brute=True).fittedvalues
visitors[['no_of_visits','HWES1']].plot(title='Holt Winters Single Exponential Smoothing grpah')```
`# Double exponential smoothing of visitors data set ( Additive and multiplicative)`
```visitors['HWES2_ADD'] = ExponentialSmoothing(visitors['no_of_visits'],trend='add').fit().fittedvalues
visitors['HWES2_MUL'] = ExponentialSmoothing(visitors['no_of_visits'],trend='mul').fit().fittedvalues
```# Split into train and test set
train_visitors = visitors[:9]
test_visitors = visitors[9:]```
```# Fit the model
fitted_model = ExponentialSmoothing(train_visitors['no_of_visits'],trend='mul',seasonal='mul',seasonal_periods=2).fit()
test_predictions = fitted_model.forecast(5)
train_visitors['no_of_visits'].plot(legend=True,label='TRAIN')
test_visitors['no_of_visits'].plot(legend=True,label='TEST',figsize=(6,4))
test_predictions.plot(legend=True,label='PREDICTION')
plt.title('Train, Test and Predicted data points using Holt Winters Exponential Smoothing')```

Basically, there are 2 models multiplicative and additive. The additive model is based on the principle that the forecasted value for each data point is the sum of the baseline values, its trend, and the seasonality components.

Similarly, the multiplicative model calculates the forecasted value for each data point as the product of the baseline values, its trend, and the seasonality components.

## Limitations of Holt-Winter’s Technique

In spite of giving the best forecasting result the Holt-Winter’s method still has certain shortcomings. One major limitation of this algorithm is the multiplicative feature of the seasonality. The issue of multiplicative seasonality is how the model performs when we have time frames with very low amounts. A time frame with a data point of 10 or 1 might have an actual difference of 9 but there is a relative difference of about 1000%, so the seasonality, which is expressed as a relative term could change drastically and should be taken care of of of when building the model.

## Final Thought

Holt winter’s algorithm has wide areas of application. It is used in various business problems mainly because of two reasons one of which is its simple implementation approach and the other one is that the model will evolve as our business requirements change.

Holt Winter’s time series model is a very powerful prediction algorithm despite being one of the simplest models. It can handle the seasonality in the data set by just calculating the central value and then adding or multiplying it to the slope and seasonality, We just have to make sure to tune in the right set of parameters, and viola, we have the best fitting model. Always remember to check the efficiency of the model using the MAPE (mean absolute percentage error) value or the RMSE(Root mean squared error) value, and the accuracy may depend on the business problem and the data set available to train and test the model.

Q1. What is the Holt-Winters algorithm?

A. The Holt-Winters algorithm is a time-series forecasting method that uses exponential smoothing to make predictions based on past observations. The method considers three components of a time series: level, trend, and seasonality, and uses them to make forecasts for future periods.

Q2. Why is Holt-Winters method used?

A. The Holt-Winters method is used for time-series forecasting because it can capture trends and seasonality in the data, making it particularly useful for predicting future values of a time series that exhibit these patterns. The method is also relatively simple and can produce accurate forecasts.

Q3. What are the three parameters of Holt-Winters?

A. The three parameters of the Holt-Winters method are alpha, beta, and gamma. Alpha represents the level smoothing factor, beta represents the trend smoothing factor, and gamma represents the seasonality smoothing factor. These parameters are given to past observations when making predictions for future time periods.

Q4. What is Holt-Winters filtering?

A. Holt-Winters filtering is a method of smoothing a time series using the Holt-Winters algorithm. The method involves taking a weighted average of past observations to produce a smoothed value for each time period in the series. The alpha, beta, and gamma smoothing factors determine the weights assigned to each observation. This smoothing process can remove noise and highlight trends and seasonality in the data, making it easier to make predictions and identify patterns in the time series. 