3

蟒蛇 3.6

我的数据集如下所示:

这是旅行预订,例如航空公司/火车/公共汽车等旅行公司。

date           bookings
2017-01-01     438
2017-01-02     167
...
2017-12-31     45
2018-01-01     748
...
2018-11-29     223

我需要这样的东西(即超出数据集的预测数据):

date           bookings
2017-01-01     438
2017-01-02     167
...
2017-12-31     45
2018-01-01     748
...
2018-11-29     223
2018-11-30     98
...
2018-12-30     73
2018-12-31     100

代码:

import pyodbc
import pandas as pd
import cufflinks as cf
import plotly.plotly as ply
from pmdarima.arima import auto_arima

sql_conn = pyodbc.connect(# connection details here)
query = #sql query here
df = pd.read_sql(query, sql_conn, index_col='date')
df.index = pd.to_datetime(df.index)

stepwise_model = auto_arima(df, start_p=1, start_q=1,
                           max_p=3, max_q=3, m=7,
                           start_P=0, seasonal=True,
                           d=1, D=1, trace=True,
                           error_action='ignore',  
                           suppress_warnings=True, 
                           stepwise=True)
stepwise_model.aic()

train = df.loc['2017-01-01':'2018-06-30']
test = df.loc['2018-07-01':]

stepwise_model.fit(train)
future_forecast = stepwise_model.predict(n_periods=len(test))
future_forecast = pd.DataFrame(future_forecast,
                               index=test.index,
                               columns=['prediction'])
pd.concat([test, future_forecast], axis=1).iplot()

结果 在此处输入图像描述

正如你所看到的,预测还差得很远,我认为问题出在没有使用正确的auto_arima参数。获取这些参数的最佳方法是什么?我也许可以反复试验,但最好了解标准/非标准程序以获得最佳拟合。

任何帮助将非常感激。

资料来源:

4

1 回答 1

2

您在 2018 年 8 月左右出现了结构性中断,但您只在 2018 年 7 月之前进行了培训。ARIMA(或任何单变量时间序列方法)将永远无法预测该结构性中断。您必须扩展您的训练数据集以包含 2018 年 8 月和 9 月的值。

请参阅此博客文章的第一部分,以更好地了解为什么会发生这种情况。

于 2018-11-30T20:32:36.897 回答