Skip to content Skip to sidebar Skip to footer

Predict Statsmodel Argument Error

I am trying to predict outofsample values for an array. Python code: import pandas as pd import numpy as np from statsmodels.tsa.arima_model import ARIMA dates = pd.date_rang

Solution 1:

The call signature of ARIMA.predict is

predict(self, params, start=None, end=None, exog=None, dynamic=False)

Thus, when you call r.predict(start='2012-07-31', end='2012-08-31'), self gets bound to r, and values are bound to start and end but the required positional arument params does not get bound. That is why you get the error

TypeError: predict() takes at least 2arguments (3 given)

Unfortunately the error message is misleading. The "3 given" refer to r, start and end. The "2 arguments" refer to the two required arguments, self and params. The problem is that the required positional argument params was not given.

To fix the problem, you need parameters. Usually you find those parameters by fitting:

r = r.fit()

before calling

pred = r.predict(start='2012-07-31', end='2012-08-31')

r.fit() returns a statsmodels.tsa.arima_model.ARIMAResultsWrapper which have the parameters "baked in" so calling ARIMAResultWrapper.fit does not require passing params.


import pandas as pd
import numpy as np
from statsmodels.tsa.arima_model import ARIMA

dates = pd.date_range('2012-07-09','2012-07-30')
series = [43.,32.,63.,98.,65.,78.,23.,35.,78.,56.,45.,45.,56.,6.,63.,45.,64.,34.,76.,34.,14.,54.]
res = pd.Series(series, index=dates)
r = ARIMA(res,(1,2,0))
r = r.fit()
pred = r.predict(start='2012-07-31', end='2012-08-31')
print(pred)

yields

2012-07-31   -39.0672222012-08-01    26.9025712012-08-02   -17.027333...2012-08-29     0.5329462012-08-30     0.5324472012-08-31     0.532780Freq:D,dtype:float64

Post a Comment for "Predict Statsmodel Argument Error"