ARIMA模型python中错误日期的预测

问题描述 投票:0回答:1

我有一个时间序列数据集。我正在使用python,pandas和statsmodels尝试预测下个月的数据。

我有每日数据:

enter image description here

首先,我运行自动变量以查看必须在Sarimax模型中放入哪些变量:

auto_arima(df['occurrences'],seasonal=True,m=7).summary()

我得到了这个结果:

enter image description here

因此,现在我将数据集分为训练数据和测试数据。我想尝试预测下个月,所以我这样做:

train = df.loc[:'2020-04-30']
test = df.loc['2020-05-01':]

我训练模型

model = SARIMAX(df['occurrences'],order=(1, 1, 1))
results = model.fit()
results.summary()
start=len(train)
end=len(train)+len(test)
predictions = results.predict(start=start, end=end, dynamic=False, typ='levels')

但是现在当我绘制预测时,我可以看到预测如何提前一天:

ax = test['occurrences'].plot(legend=True,figsize=(12,6),title=title)
predictions.plot(legend=True)
ax.autoscale(axis='x',tight=True)
ax.set(xlabel=xlabel, ylabel=ylabel);

enter image description here

如果我使用shift comand将前一天的所有预测推翻:

ax = test['occurrences'].plot(legend=True,figsize=(12,6),title=title)
predictions.shift(-1).dropna().plot(legend=True)
ax.autoscale(axis='x',tight=True)
ax.set(xlabel=xlabel, ylabel=ylabel);

enter image description here

您可以看到现在如何安装正确的日期,为什么会发生这种情况?

python statsmodels arima
1个回答
1
投票

模型会在正确的日期为您提供正确的预测。 ARIMA模型相对简单,可以根据现在和过去预测未来。因此,当模型今天看到较大的值时(例如在观测值11中),则其对明天的预测会更大。

例如,请参阅以下StackExchange问​​题和答案:https://stats.stackexchange.com/questions/330928/time-series-prediction-shifted

© www.soinside.com 2019 - 2024. All rights reserved.