首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用拟合pmdarima ARIMA模型进行预测

使用拟合pmdarima ARIMA模型进行预测
EN

Stack Overflow用户
提问于 2021-09-08 06:18:14
回答 1查看 514关注 0票数 0

我可以使用pmdarima将SARIMA模型拟合到一些数据。

代码语言:javascript
复制
import pmdarima as pm
from pmdarima.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt

# Load/split
y = pm.datasets.load_wineind()
train, test = train_test_split(y, train_size=150)

# Fit
model = pm.auto_arima(train, seasonal=True, m=12)

我可以从这些数据中做出预测,甚至可以看到样本中的预测,我可以从中计算残差。

代码语言:javascript
复制
N = test.shape[0]  # predict N steps into the future
forecasts = model.predict(N)
in_sample_forecasts = model.predict_in_sample()

但SARIMA只是一个数学模型(据我所知)。因此,我希望能够使用拟合的模型参数来完全预测其他一些序列。我能这么做吗?

例如:

代码语言:javascript
复制
# Some other series entirely
some_other_series = train + np.random.randint(0, 5000, len(train))
# The following method does not exist but illustrates the desired functionality
forecasts = model.predict_for(some_other_series, N)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-09 04:48:02

我已经找到了解决这个问题的办法。诀窍是运行另一个fit,但让优化器在幕后基本上对已经fit的参数执行no-op。我发现method='nm'实际上遵守了maxiter=0,而其他人却没有。下面是pmdarima模型的代码,但同样的想法也适用于statsmodels中的SARIMAX模型。

代码语言:javascript
复制
from copy import deepcopy
# Some other series entirely
some_other_series = train + np.random.randint(0, 5000, len(train))
# Deep copy original model for later comparison
new_model = deepcopy(model)
new_model.method = 'nm'
new_model.fit(some_other_series, maxiter=0, start_params=new_model.params())
new_model.params()
new_model.predict(12)
# Note that the params have stayed the same and predictions are different
model.params()
model.predict(12)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69097846

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档