【问题标题】:Statsmodels package in Python - issues with retrieving out-of-sample prediction of ARIMA modelPython 中的 Statsmodels 包 - 检索 ARIMA 模型的样本外预测的问题
【发布时间】:2015-09-23 16:36:08
【问题描述】:

我正在尝试检索 ARIMA 模型的样本外预测。但是,我经常收到错误,我不确定我现在应该如何进行:(代码如下:

    from statsmodels.tsa.arima_model import ARIMA
    fit = ARIMA(endog, (1,1,1)).fit()
    params = fit.params
    forecast = fit.predict(params.all(), start='2015-9-21', end='2016-9-21', typ='levels')

当我只使用时效果很好(即给我一个结果,但不是样本外的结果......)

    forecast = fit.predict(params.all(), typ='levels')

但是当我添加“开始”和“结束”日期(或仅“开始”)时,它不想工作,我经常出错。如果是第一个引用的代码块:“TypeError:predict() got multiple values for keyword argument 'start'”。我也尝试过使用 datetime 类型,但也没有用。谁能帮帮我?

【问题讨论】:

  • 自 0.6 以来已对此进行了多项修复。例如不支持结束日期时间github.com/statsmodels/statsmodels/issues/2587 我不记得开始日期有任何问题。但是,问题可能是结果实例的 predict 方法没有 params 作为参数。试试fit.predict(start='2015-9-21', end='2016-9-21', typ='levels')
  • 您好!谢谢你的提示 - 我尝试不使用参数作为参数,这次得到错误“AttributeError:'NoneType'对象没有属性'get_loc'”:(
  • @MBseekingforhelp 你已经得到答案了吗?我也得到了“AttributeError:'NoneType'对象没有属性'get_loc'”

标签: python forecasting statsmodels


【解决方案1】:

我遇到了与上面报告的错误类似的错误:

"AttributeError: 'NoneType' object has no attribute 'get_loc' "

但我意识到这是因为我传递了一个没有日期时间索引的数组(或列表),例如如果您使用 pandas 数据帧并将其输入为df.values,那么您将删除时间索引,并且 ARMA 没有触发此错误的日期信息(因此日期为无)。我建议您输入带有日期时间索引的pd.DataFramepd.Series 对象。另请参阅此线程http://pystatsmodels.narkive.com/rhX3T509/arma-predict-throws-attributeerror-with-start-and-end-dates

【讨论】:

    【解决方案2】:

    你可以使用

    fit.forecast(steps, exog=None, alpha=0.05)
    

    steps=365 根据您的 startend 参数在哪里,如果它是按月计算的。 参考this answer

    【讨论】:

      猜你喜欢
      • 2016-02-13
      • 1970-01-01
      • 2015-03-05
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-29
      相关资源
      最近更新 更多