python - 使用 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)
但是,我得到了下图,考虑到数据中存在积极趋势,它并没有真正正确地预测它。
任何线索我哪里出错或我需要添加什么?干杯
解决方案
推荐阅读
- php - Laravel 安装错误:[ErrorException] file_get_contents(): read of 8192 bytes failed with errno=9 Bad file descriptor
- php - php 应用程序中的 Tron 钱包集成
- android - 如何动态设置颤动闪屏中的持续时间?
- php - 一种形式写入数据库,另一种没有
- c++ - C++ 派生类和基复制构造函数作为指针
- java - 有没有一种快速的方法可以使用 java 获取设备上的所有音频文件?
- c++ - 使用 Visual Studio 2019 如何为没有解决方案的 C++ 代码克隆 github 存储库并构建和运行它们?
- elasticsearch - 如何在 Elasticsearch 中仅向前创建 ngram?
- git - 如何使用 SSH 登录 Github 并在命令行中创建新的存储库?
- database - Neo4j 图形性能:我应该在单独的数据库中缓存慢查询吗?