Mark Lavin
Mark Lavin

Reputation: 1242

Why doesn't Python statsmodels...SARIMAX.predict work?

I'm trying to use SARIMAX to extend a 34-element monthly time series to 35 elements, assuming a 12-month seasonal component.

However, the predict method fails with the traceback:

<ipython-input-40-151295bf5e3e> in approach_4_stationarity(data_file_name)
     27     sarima = SARIMAX( total_items_array, order = ( 1, 0, 0 ), seasonal_order = (0,0,0,12) )
     28     sarima.fit()
---> 29     next_month_item_cnt = sarima.predict( (1, 0, 0 ), start = 34, end = 34 )
     30     print( "next_month_item_cnt", next_month_item_cnt, file = sys.stderr )
     31     total_items_array = total_items_array.append( next_month_item_cnt )

/opt/conda/lib/python3.6/site-packages/statsmodels/base/model.py in predict(self, params, exog, *args, **kwargs)
    205         This is a placeholder intended to be overwritten by individual models.
    206         """
--> 207         raise NotImplementedError
    208 
    209 

How can I fix this?

Upvotes: 1

Views: 1709

Answers (2)

cfulton
cfulton

Reputation: 3195

The fit method does not affect the model object, it returns a new results object. You probably want something like the following:

model = SARIMAX(total_items_array, order=(1, 0, 0), seasonal_order=(0,0,0,12))
results = model.fit()
next_month_item_cnt = results.forecast(steps=1)

Upvotes: 5

Federico Andreoli
Federico Andreoli

Reputation: 465

As the error tells the method is not implemented and I personally never seen anything like this. Be shure to check documentation or FAQ section on the official website.

There is a solution. You can use the auto_arima function from pmdarima. It's fully automatic in identifying the parameters of SARIMA model, but (from my experience) it's time consuming and not effective at 100%. I would suggest you to see all its parameters and then you can use it like this:

from pmdarima.arima import auto_arima

step_wise=auto_arima(train_y, exogenous= train_X, start_p=1, start_q=1, 
     max_p=7, max_q=7, d=1, max_d=7, trace=True, error_action=’ignore’, 
     suppress_warnings=True, stepwise=True)

Code taken from this article. . Check official docs about auto_arima here

Upvotes: 0

Related Questions