简体   繁体   English

ARIMA model 预测不准确

[英]ARIMA model not accurate prediction

i am trying to predict the next values in a time series using the ARIMA model. Here is my code:(sorry for the typos)我正在尝试使用 ARIMA model 预测时间序列中的下一个值。这是我的代码:(抱歉打字错误)

split_val = floor(len(data_file)*0.8)
train = data_file[["Daily Confirmed"]][:split_val]
tesst = data_file[["Daily Confirmed"]][split_val:]

print(train.head())
print(tesst.head())

p = d = q = range(1, 5)

pdq = list(itertools.product(p, d, q))
# print(pdq)
bestvalues = {}
for i in pdq:
    try:
        p, d, q = i
        moodel = ARIMA(train, order=(p, d, q))
        trained_model = moodel.fit()
        bestvalues[trained_model.aic] = i
        print(trained_model.aic, " ", i)
    except:
        continue

print(bestvalues)
minaic = min(bestvalues.keys())


moodel = ARIMA(train, order=bestvalues[minaic])
trained_model = moodel.fit()

pridiction = trained_model.forecast(steps=len(tesst))[0]

comparisionn = tesst.copy()

comparisionn["forcastted"] = pridiction.tolist()
comparisionn.plot()

print(comparisionn)
print(trained_model.aic)
plt.show()

(the data is pre-processed) (数据经过预处理)

The minimum aic i can get is 2145.930883796257 and here are the predictions against the test data (only first 5):我可以获得的最小 aic 是2145.930883796257 ,这里是针对测试数据的预测(仅前 5 个):

            Daily Confirmed    forcastted
Date                                     
2020-06-22            13560  15048.987970
2020-06-23            15656  15349.247935
2020-06-24            16868  15905.260648
2020-06-25            18205  16137.086959
2020-06-26            18255  16237.232886

and here is the plot这是 plot

绘图图像

as you can see, the prediction is not accurate and i have brute forced all the values for p, d and q upto 4....如您所见,预测不准确,我已经强制将 p、d 和 q 的所有值强制为 4 ....

What might be the problem?可能是什么问题? Thanks.谢谢。

You should get better results if you update your model "daily".如果您“每天”更新 model,您应该会得到更好的结果。 Your model hasn't seen any data after July 21st while it may be August 14th.您的 model 在 7 月 21 日之后没有看到任何数据,而可能是 8 月 14 日。 ARIMA may struggle predicting 20-30 steps ahead. ARIMA 可能很难预测提前 20-30 步。 Instead - try forecasting step by step, like this:相反 - 尝试逐步预测,如下所示:

history_endog = list(train.copy(deep=True))
y_true = []
y_pred = []

for obs in test: 
    model = ARIMA(endog=history_endog, order=(p,d,q))
    model_fit = model.fit()
    forecast = model_fit.forecast()[0]

    y_true.append(obs)
    y_pred.append(forecast)
    history_endog.append(obs)

Then plot y_true and y_pred , your results should improve.然后 plot y_truey_pred ,你的结果应该会提高。 Code sample above uses lists for the sake of simplicity.为简单起见,上面的代码示例使用列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM