我正在处理时间序列问题。当我做AR模型时,一切都正确。
# Import the module for estimating an ARMA model
from statsmodels.tsa.arima_model import ARMA
# Fit the data to an AR(p) for p = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for p in range(7):
mod = ARMA(data, order=(p,0))
res = mod.fit()
# Save BIC for AR(p)
BIC[p] = res.bic
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of AR Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
但是,当我在做MA模型时:
# Fit the data to an MA(q) for q = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for q in range(7):
mod = ARMA(data, order=(0,q))
res = mod.fit()
# Save BIC for MA(q)
BIC[q] = res.bic
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of MA Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
我会得到:
ValueError: The computed initial MA coefficients are not invertible
You should induce invertibility, choose a different model order, or you can
pass your own start_params.
从non Invertible of a ARIMA model阅读答案后,我解决了错误:
# Fit the data to an MA(q) for q = 0,...,6 , and save the BIC
BIC = np.zeros(7)
for q in range(7):
try:
mod = ARMA(data, order=(0,q))
res = mod.fit()
# Save BIC for MA(q)
BIC[q] = res.bic
except:
pass
# Plot the BIC as a function of p
plt.plot(range(1,7), BIC[1:7], marker='o')
plt.xlabel('Order of MA Model')
plt.ylabel('Bayesian Information Criterion')
plt.show()
但是,我真的不明白为什么可以解决它,这就是为什么我要问这个问题。可能有人给出完整的答案。
答案 0 :(得分:0)
在尝试为ARIMA(p,d,q)模型找到可逆问题的解决方案时,我在这里跌跌撞撞。我不太确定这是否适用于您的情况,但是我以尝试输入d = 0的方式找到了解决方案。而我已经将一阶差分应用于输入ts以使序列平稳。所以当我把d = 1时,可逆性问题就解决了。
希望这会有所帮助。 谢谢。