【问题标题】:Ordering Timestamps for ARIMA model predicionARIMA 模型预测的排序时间戳
【发布时间】:2020-05-30 05:39:20
【问题描述】:

信息:

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

【问题讨论】:

    标签: python pandas arima


    【解决方案1】:

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

    【讨论】:

    • 您能详细说明两件事吗? df 是变量吗? DatatimeIndex 是从哪里来的?
    • 我收到一个 AttributeError:AttributeError: 'DataFrame' object has no attribute 'DatetimeIndex'
    • 如果df是dataframe变量,那么x等于什么?
    • 对不起我的错误。 x 是数据框变量,所以我已经更新了它。
    • 太棒了——很高兴能帮上忙!
    【解决方案2】:

    如果问题仅仅是您的数据没有正确排序,那么这应该可以工作。

    按日期排序的数据:

    prices = x.sort_index()
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-10
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多