Python 3.6
我的数据集如下:
这是旅游预订,比如说旅游公司,例如航空公司/火车/公共汽车等
date bookings
2017-01-01 438
2017-01-02 167
...
2017-12-31 45
2018-01-01 748
...
2018-11-29 223
我需要这样的数据(即数据集之外的预测数据):
^{pr2}$代码:
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
参数。获得这些参数的最佳方法是什么?我也许可以反复试验,但最好能了解标准/非标准程序以获得最佳拟合。在
任何帮助都将不胜感激。在
资料来源:
你在2018年8月左右会有一次结构性休息,但你的训练只会持续到2018年7月。ARIMA(或任何单变量时间序列方法)永远无法预测结构破裂。您必须扩展您的培训数据集,以包括2018年8月和9月的数值。在
请参阅the first section of this blog post以更好地理解发生这种情况的原因。在
相关问题 更多 >
编程相关推荐