gpt4 book ai didi

python - Statsmodels 中时间序列的交叉验证

转载 作者:太空宇宙 更新时间:2023-11-03 12:03:55 25 4
gpt4 key购买 nike

我查看了有关统计模型的示例,但没有看到很多将交叉验证应用于时间序列的示例。

假设我有这样的东西

`In [1]: from __future__ import print_function

In [2]: import numpy as np

In [3]: import statsmodels.api as sm
import pandas as pd
from statsmodels.tsa.arima_process import arma_generate_sample
np.random.seed(12345)

In [4]: import pandas as pd

In [5]: from statsmodels.tsa.arima_process import arma_generate_sample

In [6]: np.random.seed(12345)

In [7]: arparams = np.array([.75, -.25])

In [8]: maparams = np.array([.65, .35])

In [9]:

In [9]: arparams = np.r_[1, -arparams]

In [10]: maparam = np.r_[1, maparams]

In [11]: nobs = 250

In [12]: y = arma_generate_sample(arparams, maparams, nobs)

In [13]: dates = sm.tsa.datetools.dates_from_range('1980m1', length=nobs)

In [14]: y = pd.TimeSeries(y, index=dates)
/Users/pcoyle/anaconda3/bin/ipython:1: FutureWarning: TimeSeries is deprecated. Please use Series
#!/bin/bash /Users/pcoyle/anaconda3/bin/python.app

In [15]: arma_mod = sm.tsa.ARMA(y, order=(2,2))

In [16]: arma_res = arma_mod.fit(trend='nc', disp=-1)

In [17]: print(arma_res.summary())
ARMA Model Results
==============================================================================
Dep. Variable: y No. Observations: 250
Model: ARMA(2, 2) Log Likelihood -245.887
Method: css-mle S.D. of innovations 0.645
Date: Mon, 01 Aug 2016 AIC 501.773
Time: 17:51:51 BIC 519.381
Sample: 01-31-1980 HQIC 508.860
- 10-31-2000
==============================================================================
coef std err z P>|z| [95.0% Conf. Int.]
------------------------------------------------------------------------------
ar.L1.y 0.8411 0.403 2.089 0.038 0.052 1.630
ar.L2.y -0.2693 0.247 -1.092 0.276 -0.753 0.214
ma.L1.y 0.5352 0.412 1.299 0.195 -0.273 1.343
ma.L2.y 0.0157 0.306 0.051 0.959 -0.585 0.616
Roots
=============================================================================
Real Imaginary Modulus Frequency
-----------------------------------------------------------------------------
AR.1 1.5618 -1.1289j 1.9271 -0.0996
AR.2 1.5618 +1.1289j 1.9271 0.0996
MA.1 -1.9835 +0.0000j 1.9835 0.5000
MA.2 -32.1794 +0.0000j 32.1794 0.5000
-----------------------------------------------------------------------------`

我如何从该示例转向进行交叉验证。理想情况下,类似于具有时间依赖性的交叉验证。有什么建议吗?

最佳答案

也许你看看:

文本与 R 相关,但可能对您有所帮助。

关于python - Statsmodels 中时间序列的交叉验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38704205/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com