1
votes

I'm trying to run X-13-ARIMA model from statsmodels library in python 3.

I found this example in statsmodels documentation:

dta = sm.datasets.co2.load_pandas().data
dta.co2.interpolate(inplace=True)
dta = dta.resample('M').sum()

res = sm.tsa.x13_arima_select_order(dta.co2)
print(res.order, res.sorder)

results = sm.tsa.x13_arima_analysis(dta.co2)

fig = results.plot()
fig.set_size_inches(12, 5)
fig.tight_layout()

This works fine, but I also need to predict future values of this time series. The tsa.x13_arima_analysis() function contains forecast_years parameter, so I suppose it should be possible. However; the results object doesn't seem to change no matter what value of forecast_years parameter I choose.

How can I get the forecast values?

2

2 Answers

2
votes

By now you probably have this yourself. I retrieved some monthly weather data that ends in July of 2012. I entered this statement to do the analysis.

results = sm.tsa.x13_arima_analysis(s, forecast_years=3)

Then (having found that results.results is voluminous) I entered this.

open('c:/scratch/result.txt', 'w').write(results.results)

Peering through this file for 'forecast' I found the following section.

 FORECASTING
  Origin  2012.Jul
  Number         3

  Forecasts and Standard Errors of the Prior Adjusted Data
   ------------------------------
                         Standard
       Date   Forecast      Error
   ------------------------------
   2012.Aug      33.02      2.954
   2012.Sep      28.31      2.954
   2012.Oct      21.54      2.954
   ------------------------------

  Confidence intervals with coverage probability ( 0.95000
   ---------------------------------------
       Date      Lower  Forecast     Upper
   ---------------------------------------
   2012.Aug      27.23     33.02     38.82
   2012.Sep      22.52     28.31     34.10
   2012.Oct      15.75     21.54     27.33
   ---------------------------------------

forecast_years=3 seems to be taken to mean make a forecast of three months, in this case starting after July.

1
votes

forecast_years=x worked for me. Pay attention to the version of statsmodels you are running ("pip freeze | grep statsmodels") as for version 10.2 the correct parameter for forecasting horizon is <forecast_years> but in version 11.0 and higher the correct parameter is <forecast_periods>.

A simple regex should do the trick to find your forecast values:

202\d.\w{3}\s{6}\d\d.\d\d\s{5}\d\d.\d\d\s{5}\d\d.\d\d (run on each line of your results)

which would match:

2020.Feb      18.04     32.25     46.47