Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Holt-winters, ARIMA, exponential smoothing, etc. to forecast time series value in Python

For example, if I had the following time series:

x = [1999, 2000, 2001, ... , 2015]
annual_sales = [10000000, 1500000, 1800000, ... , 2800000]

How would I forecast sales for year 2016 using Holt-Winters method in Python?

like image 625
akaii Avatar asked Mar 12 '16 05:03

akaii


People also ask

Which is better Holt-Winters or ARIMA?

Thus, on the basis of these results, the Holt-Winters additive model is more efficient in predicting the prices of agricultural products than the ARIMA model. In this study, we looked at forecasting agricultural commodity prices using the time series model.

Is exponential smoothing same as Holt-Winters?

The Holt-Winters method uses exponential smoothing to encode lots of values from the past and use them to predict “typical” values for the present and future. Exponential smoothing refers to the use of an exponentially weighted moving average (EWMA) to “smooth” a time series.

Which is better exponential smoothing or ARIMA?

I found the only difference between ARIMA and Exponential smoothing model is the weight assignment procedure to its past lag values and error term. In that case Exponential should be considered much better that ARIMA due to its weight assigning method.

What is the key difference between ARIMA and exponential smoothing models?

Exponential smoothings methods are appropriate for non-stationary data (ie data with a trend and seasonal data). ARIMA models should be used on stationary data only. One should therefore remove the trend of the data (via deflating or logging), and then look at the differenced series.


1 Answers

You could use ExponentialSmoothing from Statsmodels.tsa as such:

import pandas as pd
import statsmodels.tsa.holtwinters as hw    

d = {'Year':x, 'Sales':annual_sales}
sales_df = pd.DataFrame(d)
sales_df['Year] = pd.to_datetime(sales_df['Year])
sales_df.set_index('Year', inplace=True)

model = hw.ExponentialSmoothing(sales_df).fit()

Once the model is generated, you can use predict().

It does seem, however, that it is only available for the latest version of statsmodels. See here. In my Windows 10 Anaconda based Python 3.6 installation, I use statsmodels 0.9.0 in which it works.

like image 112
Neelotpal Shukla Avatar answered Sep 21 '22 23:09

Neelotpal Shukla