【问题标题】:How to fix ARIMA MODEL bugs in Python如何修复 Python 中的 ARIMA 模型错误
【发布时间】:2019-11-15 05:06:46
【问题描述】:

我正在尝试为我的时间序列数据创建一个 ARIMA 模型。我可以对我的代码做些什么以使其顺利运行?

我正在使用 statsmodels 在 python 中创建 ARIMA 模型,但我收到错误警告

    indexedDataset_logscale.head(10)
    OUTPUT: 
                Price
    Period  
    2013-02-08  2.515274
    2013-02-11  2.526528
    2013-02-12  2.520113
    2013-02-13  2.515274
    2013-02-14  2.543961
    2013-02-15  2.544040
    2013-02-19  2.530119
    2013-02-20  2.516082
    2013-02-21  2.508786
    2013-02-22  2.5273

    #AR Model
    from statsmodels.tsa.arima_model import ARIMA

    model = ARIMA(indexedDataset_logscale, order=(0, 1, 2))
    results_AR = model.fit(disp = -1)
    plt.plot(datasetLogDiffShifting)
    plt.plot(results_AR.fittedvalues, color = 'red')
    plt.title('RSS: %.4f' %sum((results_AR.fittedvalues-datasetLogDiffShifting['Price'])**2))
    print('Plotting AR Model')



Error messages i get are: 
  • "ValueWarning:已提供日期索引,但它没有关联的频率信息,因此在例如 预测。忽略时,例如预测。',ValueWarning)

  • 8 plt.title('RSS: %.4f' %sum((results_AR.fittedvalues-datasetLogDiffShifting['Price'])**2)) TypeError: 'str' 对象不可调用

【问题讨论】:

    标签: python pandas statsmodels


    【解决方案1】:

    1) 您的索引似乎没有设置频率 尝试在华宇之前添加这个

    df.index.freq = 'D'
    

    D 代表每日时间戳,看起来你不是线性/规则的,很难定义查看问题中的内容。检查 pandas 中的其他频率选项。

    为避免出现警告,请在脚本开头键入:

    #Clear console
    import warnings
    warnings.filterwarnings("ignore")
    

    【讨论】:

      【解决方案2】:

      问题是在您的数据中,索引似乎是每天,但有些日期不是连续的天。您可以提供缺失的日期,然后为这些日期插入值,如下所示:

      df = df.resample('D').mean()
      df["Price"] = df["Price"].interpolate(method='linear', axis=0).ffill().bfill()
      

      然后您将能够构建模型并绘制拟合值。

      【讨论】:

      • @ShadowWalker 很高兴听到这个消息 - 你应该支持/接受答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 2017-02-10
      • 2022-07-06
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多