model = ARIMA(data[0:45], (p, 1, q)).fit()啥意思,为什么会报错ValueError: endog and exog matrices are different sizes
时间: 2024-05-24 07:12:12 浏览: 21
这段代码是在使用ARIMA模型对数据进行拟合和预测。其中data[0:45]是传入的时间序列数据,(p, 1, q)是ARIMA模型的参数,p表示自回归项数,q表示移动平均项数,1表示差分阶数。
报错ValueError: endog and exog matrices are different sizes表示传入的数据(endog)和外生变量(exog)的矩阵尺寸不同。这可能是因为在ARIMA模型中没有使用外生变量,因此需要删除exog参数或者将其设置为None,使endog和exog尺寸相同。
相关问题
model = ARIMA(data, order=(1,1,1)) model_fit = model.fit(disp=0)报错fit() got an unexpected keyword argument 'disp'
这个问题可能是由于您的statsmodels版本过低引起的。请尝试使用以下代码升级statsmodels:
```
!pip install statsmodels --upgrade
```
然后再次运行您的代码,看看是否解决了问题。如果仍然存在问题,可以尝试使用以下代码替换您的代码:
```
model = ARIMA(data, order=(1,1,1))
model_fit = model.fit()
```
这应该可以解决您的问题。
把model = ARIMA(data, (p, 1, q)).fit()变成sarimax的代码
要将ARIMA转换为SARIMAX,需要添加季节性差异参数,并将季节性差异设置为False。SARIMAX的代码如下所示:
```python
from statsmodels.tsa.statespace.sarimax import SARIMAX
model = SARIMAX(data, order=(p, 1, q), seasonal_order=(P, D, Q, s), trend='c', enforce_stationarity=False, enforce_invertibility=False).fit()
```
其中,P、D、Q和s分别是季节性差异的自回归、差分和移动平均数,trend指定趋势项的类型,enforce_stationarity和enforce_invertibility分别指定是否强制满足平稳性和可逆性的要求。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)