首页 > 解决方案 > ARIMA 模型预测的订购时间戳

问题描述

信息:

我正在尝试预测比特币的价格,作为测试并使其更容易,在我的数据中我最近的日期时间后 1 天。所以 t = 2020 年 5 月 27 日,t + 1 = 2020 年 5 月 28 日。

所以我加载了我的数据:

x = pd.read_csv('btcdata.csv', header=0, parse_dates=['Date'], index_col=0)
close = x.Close

这就是它的样子.head()

Date
2020-05-27    8854.32
2020-05-26    8844.42
2020-05-25    8899.31
2020-05-24    8715.73
2020-05-23    9181.76

这有一个小问题,最近的日期位于顶部,最旧的日期位于底部。大多数日期都是按相反的方式组织的,至少 ARIMA 模型是这样看待它的。

因此,当我使用该模型进行拟合和预测时.forecast(),这是我的output[0]

[381.59648517]

这实际上与.tail()我的数据更匹配:

Date
2014-12-05    377.1
2014-12-04    377.1
2014-12-03    378.0
2014-12-02    378.0
2014-12-01    370.0

问题/问题:

我该如何解决这个问题,并以某种方式对其进行排序,以便 ARIMA 模型知道哪个是我最近的日期t并知道预测t + 1

同样,每次我适合我的模型时,都会出现这两个警告。它可能与问题有关:

ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.
ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.

标签: pythonpandasarima

解决方案


ValueWarning: A date index has been provided, but it has no associated frequency information and so will be ignored when e.g. forecasting.表示 ARIMA 不了解您的数据格式。

这应该将所有内容转换为 DatetimeIndex,频率为天。

x.index = pd.DatetimeIndex(x.index).to_period('D')

ValueWarning: A date index has been provided, but it is not monotonic and so will be ignored when e.g. forecasting.表示数据未排序,因此输入以下行:

x = x.sort_index()

推荐阅读