简体   繁体   English

statsmodels.tsa.arima_model:TypeError:“系列”对象不可调用

[英]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 . 通过建立一个ARMA模型后statsmodels.tsa.arima_model.ARMA ,我想用给MESURE模型的误差.resid()之类的方法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 : 实际上, statsmodels.tsa.arima_model.ARMAResults.resid()的源代码如下:

@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 () . 使用不带括号() arma11.resid

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. statsmodels的文档对此有点困惑,因为sphinx将这些缓存的属性作为一种方法呈现,并包括括号,即使我们在不带括号的情况下使用它也是如此。

General Python tip: If the error message says that an object is not callable, then we can try without calling it, ie without the () . Python的一般提示:如果错误消息表明一个对象不可调用,那么我们可以尝试不调用它,即不使用() (It also happens to me that I don't remember which is an attribute and which is a method or callable.) (我也碰巧,我不记得哪个是属性,哪个是方法或可调用。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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