在 pandas 数据帧中使用最大似然估计器的自回归 (AR) 模型:correlate() 得到了意外的关键字参数 'old behavior'

Auto Regressive (AR) model using Maximum Likelihood Estimator in pandas dataframe: correlate() got an unexpected keyword argument 'old behavior'

我有一个 pandas 数据框的子集,其中包含我想使用 statsmodel 使用 AR 或 ARIMA 模型进行分析的时间序列:

data_sci = H_Clinton_social_vector.Florida

数据如下所示:

Date
    2015-09-28     587
    2015-10-05     582
    2015-10-12     606
    2015-10-19     698

我的 AR 模型是这样创建的,每周汇总时间序列:

ar_model = sm.tsa.AR(data_sci, freq='W')
ar_model
<statsmodels.tsa.ar_model.AR at 0x1178f5490>

接下来,我想对 AR 参数进行最大似然估计 (MLE) 拟合,滞后半年:

ar_res = ar_model.fit(maxlag=26, method='mle')

我得到以下结果:

correlate() got an unexpected keyword argument 'old behavior'

我不明白问题是什么,我认为这与数据的自动关联有关,因为 correlate() 参数。我的数据中有很高的自相关性,所以这应该没问题。

我对 stasmodels 不是很熟悉,更喜欢避免从头开始编写 AR 或 ARIMA 模型。

您需要将 numpy 降级到 1.9.2 或更低版本,刚刚测试并且您的代码不再出现此错误。这是由于在 _presample_varcov 中调用 np.correlate(),其中 statsmodels.tsa.armodel 计算预采样方差协方差的倒数。

Numpy 已于 2015 年 6 月左右 1.10 弃用 multiarray.correlate()old behavior),但 statsmodels 已未在这方面进行更新(0.6.1 日期自 2014 年 12 月起)。

经过一些研究,问题是 statsmodel 与 numpy 1.10 不兼容。虽然我有最新版本的 stasmodel,但自相关存在内部问题(与最新版本的 numpy 不兼容),需要在 Github.

安装主代码

首先,我找出了我拥有的 stasmodels 依赖项的版本:

Python >= 2.6, including Python 3.x
NumPy >= 1.5.1
SciPy >= 0.9.0
Pandas >= 0.7.1
Patsy >= 0.3.0

它们都很好,所以为了从源代码安装,我需要 Cython >= 20.1,我从 here 下载的。解压缩,导航到该目录并执行:

python setup.py install

完成后,导航到从 Github 下载的 statsmodel 副本,然后构建 stasmodel:

python setup.py install

你会看到:

Cythonizing sources
Processing statsmodels/nonparametric/_smoothers_lowess.pyx
Processing statsmodels/nonparametric/linbin.pyx
Processing statsmodels/tsa/kalmanf/kalman_loglike.pyx
Processing statsmodels/tsa/statespace/_statespace.pyx.in

等一段时间后,您将拥有最新版本的 statsmodel。现在我的 AR 模型工作正常,尽管有一些您可以忽略或禁用的警告。