简体   繁体   English

Python 中 ARIMA 的样本内预测区间

[英]In-sample prediction interval for ARIMA in Python

I am using the statsmodels ARIMA to build models and give estimates.我正在使用 statsmodels ARIMA 来构建模型并给出估计。 predict() can be used to give the in-sample model estimates/results. predict() 可用于给出样本内 model 估计/结果。 forecast() can be used to give out-of-sample estimates and prediction intervals. predict() 可用于给出样本外估计和预测区间。 I need the prediction intervals for the in-sample model results.我需要样本内 model 结果的预测区间。 Is there any operation that can be used?有什么可以使用的操作吗? Can forecast() be called for in-sample?样本内可以调用 predict() 吗?

If possible, you should switch to using the SARIMAX model, which has more features and will be better supported going forwards (the ARIMA model will be deprecated in the next release).如果可能,您应该切换到使用 SARIMAX model,它具有更多功能并且将在未来得到更好的支持(ARIMA model 将在下一个版本中弃用)。 The results object will then have methods called get_prediction and get_forecast that will allow you to create a new results object that is extended with your new values.结果 object 然后将具有称为get_predictionget_forecast的方法,它们将允许您创建一个新的结果 object 并使用您的新值进行扩展。

The syntax for getting prediction intervals is a little different, but it supports intervals both in-sample and out-of-sample.获取预测区间的语法略有不同,但它支持样本内和样本外的区间。

from statsmodels.tsa.api import SARIMAX
model = SARIMAX(timeseries, order=(1, 0, 6))
results = model.fit()

pred = results.get_prediction(start=..., end=...)
print(pred.predicted_mean)        # prediction
print(pred.conf_int(alpha=0.05))  # confidence interval

fcast = results.get_forecast(steps=...)
print(fcast.predicted_mean)        # forecast
print(fcast.conf_int(alpha=0.05))  # confidence interval

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

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