ARIMAResults.plot_predict(start=None, end=None, exog=None, dynamic=False, alpha=0.05, plot_insample=True, ax=None)
[source]
Plot forecasts
Parameters: |
|
---|---|
Returns: |
fig – The plotted Figure instance |
Return type: |
matplotlib.Figure |
>>> import statsmodels.api as sm >>> import matplotlib.pyplot as plt >>> import pandas as pd >>> >>> dta = sm.datasets.sunspots.load_pandas().data[['SUNACTIVITY']] >>> dta.index = pd.DatetimeIndex(start='1700', end='2009', freq='A') >>> res = sm.tsa.ARMA(dta, (3, 0)).fit() >>> fig, ax = plt.subplots() >>> ax = dta.loc['1950':].plot(ax=ax) >>> fig = res.plot_predict('1990', '2012', dynamic=True, ax=ax, ... plot_insample=False) >>> plt.show()
(Source code, png, hires.png, pdf)
This is hard-coded to only allow plotting of the forecasts in levels. It is recommended to use dates with the time-series models, as the below will probably make clear. However, if ARIMA is used without dates and/or start
and end
are given as indices, then these indices are in terms of the original, undifferenced series. Ie., given some undifferenced observations:
1970Q1, 1 1970Q2, 1.5 1970Q3, 1.25 1970Q4, 2.25 1971Q1, 1.2 1971Q2, 4.1
1970Q1 is observation 0 in the original series. However, if we fit an ARIMA(p,1,q) model then we lose this first observation through differencing. Therefore, the first observation we can forecast (if using exact MLE) is index 1. In the differenced series this is index 0, but we refer to it as 1 from the original series.
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/generated/statsmodels.tsa.arima_model.ARIMAResults.plot_predict.html