ARIMA 模型中错误天数的预测 python
Prediction in incorrect days in ARIMA model python
我有一个时间序列数据集。我正在使用 python、pandas 和 statsmodels 来尝试预测下个月的数据。
我有每日数据:
首先我 运行 autoarima 看看我必须在我的 Sarimax 模型中放入哪些变量:
auto_arima(df['occurrences'],seasonal=True,m=7).summary()
我得到了这个结果:
所以,现在我将数据集拆分为训练数据和测试数据。我想尝试预测下个月,所以我这样做:
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);
如果我使用 shift 命令将前一天的所有预测设为 asing:
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);
你可以看到现在是如何在正确的日期安装的,为什么会这样?
该模型在正确的日期为您提供正确的预测。 ARIMA 模型相对简单,根据现在和过去预测未来。因此,当模型今天看到一个大值时(例如在观察 11 中),它对明天的预测更大。
例如,查看这个 StackExchange 问题和答案:https://stats.stackexchange.com/questions/330928/time-series-prediction-shifted
我有一个时间序列数据集。我正在使用 python、pandas 和 statsmodels 来尝试预测下个月的数据。
我有每日数据:
首先我 运行 autoarima 看看我必须在我的 Sarimax 模型中放入哪些变量:
auto_arima(df['occurrences'],seasonal=True,m=7).summary()
我得到了这个结果:
所以,现在我将数据集拆分为训练数据和测试数据。我想尝试预测下个月,所以我这样做:
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);
如果我使用 shift 命令将前一天的所有预测设为 asing:
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);
你可以看到现在是如何在正确的日期安装的,为什么会这样?
该模型在正确的日期为您提供正确的预测。 ARIMA 模型相对简单,根据现在和过去预测未来。因此,当模型今天看到一个大值时(例如在观察 11 中),它对明天的预测更大。
例如,查看这个 StackExchange 问题和答案:https://stats.stackexchange.com/questions/330928/time-series-prediction-shifted