python - 带有熊猫数据框的 ARIMA 模型
问题描述
我有以下数据集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))
.
你知道这意味着什么以及我该如何解决它吗?
解决方案
此错误表明ARIMA
需要一个类似数组的对象,但您已经传递了 a DataFrame
。
这可以通过传递test_1["Frequency"]
而不是 just来解决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()
推荐阅读
- file - 使用带有共享文件指针的 MPI-IO 将巨大的数组写入单个文件
- reactjs - 我应该将 access_token 存储在 localStorage+Redux 中还是 axios 默认值中?
- r - 如何根据另一个数据帧对一个数据帧执行操作?
- scala - 如何在 Spark 中使用 from_json() 数据框?
- woocommerce - 如何保存个人资料图片并在编辑帐户页面 woo-commerce 中显示
- arrays - 如何使用 ruby 从这个数组中获取所有元素?
- mongodb - 如何在 MONGODB 条件下使用 CASE 语句
- json - 根据golang中的条件执行自我解组方法或默认解组方法
- angular - 如何使用 CAS 针对 SpringBoot 后端授权 Angular5 应用程序
- javascript - 优化了色彩渲染功能