带统计模型的ARMA样本外预测 [英] ARMA out-of-sample prediction with statsmodels

查看:311
本文介绍了带统计模型的ARMA样本外预测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用statsmodels来拟合ARMA模型.

I'm using statsmodels to fit a ARMA model.

import statsmodels.api as sm
arma    = sm.tsa.ARMA(data, order =(4,4));
results = arma.fit( full_output=False, disp=0);

其中data是一维数组.我知道要获得样本中的预测:

Where data is a one-dimensional array. I know to get in-sample predictions:

pred = results.predict();

现在,给定第二个数据集data2,我如何使用先前校准的模型来生成基于此观察结果的带有预测(预测)的序列?

Now, given a second data set data2, how can I use the previously calibrated model to generate a series with forecasts (predictions) based in this observations?

推荐答案

我认为这是有问题的.如果您在github上提交文件,我将更可能记得添加类似的内容.预测机制(尚未)可作为面向用户的功能使用,因此您必须执行类似的操作.

I thought there was an issue for this. If you file one on github, I'll be more likely to remember to add something like this. The prediction machinery is not (yet) available as user-facing functions, so you'd have to do something like this.

如果您已经拟合了模型,则可以执行此操作.

If you've fit a model already, then you can do this.

# this is the nsteps ahead predictor function
from statsmodels.tsa.arima_model import _arma_predict_out_of_sample
res = sm.tsa.ARMA(y, (3, 2)).fit(trend="nc")

# get what you need for predicting one-step ahead
params = res.params
residuals = res.resid
p = res.k_ar
q = res.k_ma
k_exog = res.k_exog
k_trend = res.k_trend
steps = 1

_arma_predict_out_of_sample(params, steps, residuals, p, q, k_trend, k_exog, endog=y, exog=None, start=len(y))

这是新的预测,尚需1步.您可以将此设置为y,并且需要更新残差.

This is a new prediction 1 step ahead. You can tack this on to y, and you'll need to update your residuals.

这篇关于带统计模型的ARMA样本外预测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆