例如,如果我有以下时间序列:
x = [1999, 2000, 2001, ... , 2015]
annual_sales = [10000000, 1500000, 1800000, ... , 2800000]
如何使用Python中的Holt-Winters方法预测2016年的销售额?
答案 0 :(得分:3)
您可以使用Statsmodels.tsa中的ExponentialSmoothing:
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()
生成模型后,您可以使用predict()
。
但是,它似乎只适用于最新版本的statsmodels。见here。在我的基于Windows 10 Anaconda的Python 3.6安装中,我使用了statsmodels 0.9.0,它可以在其中运行。