简体   繁体   中英

statsmodels.tsa.arima_model : TypeError: 'Series' object is not callable

After building an ARMA model using statsmodels.tsa.arima_model.ARMA , I want to mesure the model's error using the .resid() method of the class ARMAResult . However, during the execution, I got an error :

Traceback (most recent call last):
  File "smtest.py", line 161, in <module>
    arma(df, 'input')
  File "smtest.py", line 81, in arma
    print arma11.resid()
TypeError: 'Series' object is not callable

Actually, the source code of statsmodels.tsa.arima_model.ARMAResults.resid() is the following :

@cache_readonly
def resid(self):
    return self.model.geterrors(self.params)

And part of my code :

def arma(df, colname):
    """
    Compute the ARMA result for dataframe provided, than plot

    Parameters
    ----------
    df : dataframe
    colname : column name in the dataframe df
    """
    values_realtime = df[colname]
    arma11 = sm.tsa.ARMA(values_realtime, (1, 1)).fit()
    arma12 = sm.tsa.ARMA(values_realtime, (1, 2)).fit()
    arma13 = sm.tsa.ARMA(values_realtime, (1, 3)).fit()
    arma31 = sm.tsa.ARMA(values_realtime, (3, 1)).fit()
    arma41 = sm.tsa.ARMA(values_realtime, (4, 1)).fit()
    values_predict_arma11 = arma11.predict()
    values_predict_arma12 = arma12.predict()
    values_predict_arma13 = arma13.predict()
    values_predict_arma31 = arma31.predict()
    values_predict_arma41 = arma41.predict()
    # get errors I
    values_error_arma11 = values_predict_arma11 - values_realtime
    values_error_arma12 = values_predict_arma12 - values_realtime
    values_error_arma13 = values_predict_arma13 - values_realtime
    values_error_arma31 = values_predict_arma31 - values_realtime
    values_error_arma41 = values_predict_arma41 - values_realtime
    # get errors II
    print arma11.resid()
    # ...

Can somebody tell me what should I do to resolve the problem ? Thanks.

Use arma11.resid without parentheses () .

Explanation:

Many results in the models are calculated lazily, that is, they are only calculated on demand, but then stored for further use. This means that these results are essentially cached properties, implemented through a decorator.

The documentation of statsmodels is a bit confusing on this because sphinx renders these cached properties as a method and includes the parentheses, even though we use it without parenthesis.

General Python tip: If the error message says that an object is not callable, then we can try without calling it, ie without the () . (It also happens to me that I don't remember which is an attribute and which is a method or callable.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM