简体   繁体   English

如何修复Python中的ARIMA MODEL错误

[英]How to fix ARIMA MODEL bugs in Python

I'm trying to create an ARIMA Model for my time series data. 我正在尝试为我的时间序列数据创建一个ARIMA模型。 What can i do to my code for it to run smoothly? 我该如何对其代码进行平滑处理才能使其正常运行?

I'm using statsmodels to create the ARIMA model in python but i'm getting error warnings 我正在使用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: A date index has been provided, but it has no associated frequency information and so will be ignored when eg forecasting. ignored when eg forecasting.', ValueWarning) “ ValueWarning:提供了日期索引,但没有相关的频率信息,因此在进行预测时将被忽略。例如在进行预测时将被忽略。”,ValueWarning)

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

1) It seems your index doesn't have set frequency Try adding this befor Arima 1)看来您的索引没有设定频率尝试在Arima之前添加此

df.index.freq = 'D'

D is for daily timestamp, it seems your is not linear/regular, hard to define looking at what's in the question. D是每天的时间戳,似乎您不是线性/有规律的,很难定义问题所在。 Check other frequency option in pandas. 检查熊猫中的其他频率选项。

To avoid warnings type this at the beginning of the script: 为避免警告,请在脚本开头键入以下内容:

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

The problem is that in your data, the index seems to be daily, but some dates are not consecutive days. 问题在于,在您的数据中,索引似乎是每日的,但某些日期不是连续的天。 You can supply missing dates and then interpolate values for these dates, as follows: 您可以提供缺少的日期,然后插值这些日期的值,如下所示:

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

You will then be able to build a model and plot the fitted values. 然后,您将能够构建模型并绘制拟合值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM