简体   繁体   English

ARIMA model 与 pandas dataframe

[英]ARIMA model with pandas dataframe

I have the following dataset test_1我有以下数据集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

where Frequency is a calculated column with the frequency of users by date.其中Frequency是按日期计算的用户频率列。

I would like to predict the future trends and to do it I am considering an ARIMA model.我想预测未来的趋势,为此我正在考虑使用 ARIMA model。 I have used this code我用过这段代码

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

but I have got this error: ValueError: Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).但我收到了这个错误: ValueError: Pandas data cast to numpy dtype of object. Check input data with np.asarray(data). ValueError: Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).

due to model = ARIMA(test_1, order=(5,1,0)) .由于model = ARIMA(test_1, order=(5,1,0))

Do you know what it means and how I could fix it?你知道这意味着什么以及我该如何解决它吗?

This error states that ARIMA expects an array-like object, but you've passed a DataFrame instead.此错误表明ARIMA需要一个类似数组的 object,但您已经传递了DataFrame

This can be solved by passing the test_1["Frequency"] instead of just test_1 .这可以通过传递test_1["Frequency"]而不仅仅是test_1来解决。 Also, I will fix some of the other things that I encountered in your code:另外,我将修复我在您的代码中遇到的其他一些问题:

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

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

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