ARIMA 模型预测的排序时间戳

Ordering Timestamps for ARIMA model predicion

信息:

我正在尝试预测比特币的价格,作为测试并使其更容易,在我数据中的最新日期时间后 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

Question/Problem:

我该如何解决这个问题,并以某种方式对其进行排序,以便 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.

如果问题只是您的数据排序不正确,那么这应该有效。

按日期排序的数据:

prices = x.sort_index()

或者,如果您只想要 5 个最近的数据点:

latest_prices = x.sort_index().iloc[-5:]

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()