我有一个 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 模型。
最佳答案
经过一些研究,问题是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 模型工作正常,尽管有一些您可以忽略或禁用的警告。
关于python - 在 pandas 数据帧 : correlate() got an unexpected keyword argument 'old behavior' 中使用最大似然估计器的自动回归 (AR) 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34377683/