'ARIMAResults' object has no attribute 'plot_predict' error

Question:

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?

Asked By: Naman Nagelia

||

Answers:

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

enter image description here

Answered By: AlexK
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.