There's more...

There is an extension of Holt's method called Holt-Winter's Seasonal Smoothing. It accounts for seasonality in the time series. There is no separate class for this model, but we can tune the ExponentialSmoothing class by adding the seasonal and seasonal_periods arguments.

Without going into too much detail, this method is most suitable for data with trend and seasonality. There are two variants of this model and they have either additive or multiplicative seasonalities. In the former one, the seasonal variations are more or less constant throughout the time series. In the latter one, the variations change in proportion to the passing of time.

We begin by fitting the models:

SEASONAL_PERIODS = 12

# Holt-Winter's model with exponential trend
hw_1 = ExponentialSmoothing(goog_train,
trend='mul',
seasonal='add',
seasonal_periods=SEASONAL_PERIODS).fit()
hw_forecast_1 = hw_1.forecast(test_length)

# Holt-Winter's model with exponential trend and damping
hw_2 = ExponentialSmoothing(goog_train,
trend='mul',
seasonal='add',
seasonal_periods=SEASONAL_PERIODS,
damped=True).fit()
hw_forecast_2 = hw_2.forecast(test_length)

Then, we plot the results:

goog.plot(color=COLORS[0],
title="Holt-Winter's Seasonal Smoothing",
label='Actual',
legend=True)

hw_1.fittedvalues.plot(color=COLORS[1])
hw_forecast_1.plot(color=COLORS[1], legend=True,
label='Seasonal Smoothing')

phi = hw_2.model.params['damping_slope']
plot_label = f'Seasonal Smoothing (damped with $phi={phi:.4f}$)'

hw_2.fittedvalues.plot(color=COLORS[2])
hw_forecast_2.plot(color=COLORS[2], legend=True,
label=plot_label)

Executing the code results in the following plot:

From the plotted forecasts, we can see that the model is more flexible in comparison to SES and Holt's linear trend models. The extreme fitted values at the beginning of the series are a result of not having enough observations to look back on (we selected seasonal_periods=12 as we are dealing with monthly data). 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.11.20