我刚开始探索时间序列。我有这样的数据框(df)。
Volume Year Month
718394219 2013 01
763723622 2014 01
762225057 2015 01
787479774 2016 01
845614054 2017 01
我希望预测2018年的销售量。由于我只是想了解基本情况,因此预测的准确性不需要太高。
我制定了这样的方法,即将我的移动平均函数与实际数据绘制在一起。
def plotMovingAverage(series, n):
"""
series - dataframe with timeseries
n - rolling window size
"""
rolling_mean = series.rolling(window=n).mean()
#rolling_std = series.rolling(window=n).std()
#upper_bond = rolling_mean+1.96*rolling_std
#lower_bond = rolling_mean-1.96*rolling_std
plt.figure(figsize=(15,5))
plt.title("Moving average\n window size = {}".format(n))
plt.plot(rolling_mean, "g", label="Rolling mean trend")
#plt.plot(upper_bond, "r--", label="Upper Bond / Lower Bond")
#plt.plot(lower_bond, "r--")
plt.plot(series[n:], label="Actual values")
plt.legend(loc="upper left")
plt.grid(True)
但是,我不知道如何预测 t+1
的值。
对于指数平滑同样的问题。
def exponential_smoothing(series, alpha):
result = [series[0]] # first value is same as series
for n in range(1, len(series)):
result.append(alpha * series[n] + (1 - alpha) * result[n-1])
return result