蟒蛇 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
参数。获取这些参数的最佳方法是什么?我也许可以反复试验,但最好了解标准/非标准程序以获得最佳拟合。
任何帮助将非常感激。
资料来源: