首页 > 解决方案 > 使用 ARIMA 进行预测

问题描述

所以我一直在尝试预测我在网上找到的这个流量数据。我有以下数据框。我已经做到了,因此数据是固定的,并且我已经使用所有数据预测了预测。

在此处输入图像描述

from statsmodels.tsa.arima_model import ARIMA

model = ARIMA(stationary_total_vehicles['all_motor_vehicles'], order = (3,0,0))
results = model.fit(disp=0)

stationary_total_vehicles['forecast'] = results.predict()
stationary_total_vehicles_plot = stationary_total_vehicles[1:]
stationary_total_vehicles_plot.set_index(pd.DatetimeIndex(stationary_total_vehicles_plot['year']))
stationary_total_vehicles_plot[['all_motor_vehicles', 'forecast']].plot(figsize=(12,8))

这是创建绘图并拟合数据的代码,我得出了下图。(不太确定年份不是在底部,但它是年份。

在此处输入图像描述

然后我想预测 30 年后它会是什么样子。我使用下面的代码预测未来 30 年。它从数据帧中的最后一个数据点到“未来”的 30 个数据点。

forecast = results.predict(start=len(stationary_total_vehicles_plot['all_motor_vehicles']), end = len(stationary_total_vehicles_plot['all_motor_vehicles']) + 30).rename('Forecast')
stationary_total_vehicles_plot['all_motor_vehicles'].plot(figsize = (12, 5), legend = True)
forecast.plot(legend=True)

但是,我得到了下图,考虑到数据中存在积极趋势,它并没有真正正确地预测它。

在此处输入图像描述

任何线索我哪里出错或我需要添加什么?干杯

标签: pythonforecastingarima

解决方案


推荐阅读