简体   繁体   中英

'ARIMAResults' object has no attribute 'plot_predict' error

In stats models I have this code

from statsmodels.tsa.arima.model import ARIMA

from statsmodels.graphics.tsaplots import plot_predict

df1.drop(df1.columns.difference(['PTS']), 1, inplace=True)      
model = ARIMA(df1.PTS, order=(0, 15,0))
res = model.fit()
res.plot_predict(start='2021-10-19', end='2022-04-05')
plt.show()

However when it goes to plt.show I get the ARIMA results object has no attribute plot predict. What do i do to fix this?

The .plot_predict() method no longer exists with the changes to the ARIMA classes in statsmodels version 13. So, just use the plot_predict() function that you already imported in your code. Here is an example with a different dataset:

import matplotlib.pyplot as plt
import pandas as pd
import statsmodels.api as sm
from statsmodels.graphics.tsaplots import plot_predict
from statsmodels.tsa.arima.model import ARIMA

dta = sm.datasets.sunspots.load_pandas().data[['SUNACTIVITY']]
dta.index = pd.date_range(start='1700', end='2009', freq='A')
res = ARIMA(dta, order=(0,2,0)).fit()
fig, ax = plt.subplots()
ax = dta.loc['1950':].plot(ax=ax)
plot_predict(res, '1990', '2012', ax=ax)
plt.show()

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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