最近看到一个餐厅销量预测的代码,奈何目前statsmodels 版本已经是0.13.2,之前代码运行报错
p,q = bic_matrix.stack().idxmin()
一开始以为是数据类型问题,当我输出时
print(bic_matrix)
得到的结果是
所以这里发现肯定是上面没有获取到值,找到这里发现就是关键
于是乎注释try except 再次运行得到
NotImplementedError:
statsmodels.tsa.arima_model.ARMA and statsmodels.tsa.arima_model.ARIMA have
been removed in favor of statsmodels.tsa.arima.model.ARIMA (note the .
between arima and model) and statsmodels.tsa.SARIMAX.
statsmodels.tsa.arima.model.ARIMA makes use of the statespace framework and
is both well tested and maintained. It also offers alternative specialized
parameter estimators.
这下就找到病因了,百度搜索,发现这位大佬的文章
链接:https://blog.youkuaiyun.com/m0_52118763/article/details/123776168
使用大佬的方法,还是有点小问题
ValueError: endog and exog matrices are different sizes
发现是参数问题,于是添加了参数,成功运行
其他地方也替换修改,但是在最后,发现了一个问题
修改成下面的样子,就可以了正常输出数据了
这里确实没有弄懂,如果有知道的大佬,劳烦告知一声,非常感谢@开始king大佬的文章指点了迷津,最后献上完整代码
# -*- coding: utf-8 -*-
import pandas as pd
discfile = '../data/arima_data.xls'
forecastnum = 5
data = pd.read_excel(discfile, index_col = '日期')
# 时序图
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
data.plot()
plt.show()