我刚刚开始探索时间序列。我有这样的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
最佳答案
预测 pandas
自己没有实现任何预测机制。预测是一个机器学习领域,为此使用适当的工具或手动实现您的算法。
您可以使用 sklearn 中实现的线性模型或者对于像 SARIMAX 这样的特殊时间序列预测模型,使用 statsmodels见how in notebook
对于窗口计算 pandas
有一组特殊的函数看EWM在文档中
关于python - 如何使用移动平均值/滚动平均值预测下一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48973632/