【问题标题】:ARIMA model with pandas dataframe带有熊猫数据框的 ARIMA 模型
【发布时间】:2020-10-10 18:22:16
【问题描述】:

我有以下数据集test_1

Date    Frequency
0   2020-01-20  10
1   2020-01-21  2
2   2020-01-22  1
3   2020-01-23  10
4   2020-01-24  6
... ... ...
74  2020-04-04  7
75  2020-04-05  9
76  2020-04-06  8
77  2020-04-07  6
78  2020-04-08  1

其中Frequency 是按日期计算的用户频率列。

我想预测未来趋势,为此我正在考虑使用 ARIMA 模型。 我用过这段代码

# fit model
model = ARIMA(test_1, order=(5,1,0))
model_fit = model.fit(disp=0)
print(model_fit.summary())
# plot residual errors
residuals = DataFrame(model_fit.resid)
residuals.plot()
pyplot.show()
residuals.plot(kind='kde')
pyplot.show()
print(residuals.describe())

但我收到此错误:ValueError: Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).

由于model = ARIMA(test_1, order=(5,1,0))。

你知道这意味着什么以及我该如何解决它吗?

【问题讨论】:

    标签: python pandas time-series arima


    【解决方案1】:

    此错误表明 ARIMA 需要一个类似数组的对象,但您传递的是 DataFrame。

    这可以通过传递test_1["Frequency"] 而不仅仅是test_1 来解决。另外,我将修复我在您的代码中遇到的一些其他问题:

    import pandas as pd
    from statsmodels.tsa.arima_model import ARIMA
    import matplotlib.pyplot as pyplot
    
    # fit model
    model = ARIMA(test_1["Frequency"], order=(5,1,0)) #<--- change this
    model_fit = model.fit(disp=0)
    print(model_fit.summary())
    # plot residual errors
    residuals = pd.DataFrame(model_fit.resid)
    residuals.plot(kind='kde')
    print(residuals.describe())
    pyplot.show()
    

    【讨论】:

    • 非常感谢 Anwarvic。我遇到了另一个错误:----&gt; 6 residuals = DataFrame(model_fit.resid) 7 residuals.plot() 8 pyplot.show() NameError: name 'DataFrame' is not defined。您认为与之前的错误有什么关系吗?
    猜你喜欢
    • 2015-01-26
    • 2017-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-17
    • 2017-10-19
    • 1970-01-01
    • 2018-03-02
    相关资源
    最近更新 更多