statsmodel ARMA样本预测

时间:2018-01-14 16:44:34

标签: python statistics time-series statsmodels autoregressive-models

我使用statsmodel ARMA()来估算模拟MA(1)进程:

import statsmodels.tsa.api as smt
import numpy as np
import matplotlib.pyplot as plt

# Simulate an MA(1) process
n = int(1000)
alphas = np.array([0.])
betas = np.array([0.6])
ar = np.r_[1, -alphas]
ma = np.r_[1, betas]
ma1 = smt.arma_generate_sample(ar=ar, ma=ma, nsample=n) #input

# Fit the MA(1) model to our simulated time series
max_lag = 30
mdl = smt.ARMA(ma1, order=(0, 1)).fit(maxlag=max_lag, method='mle', trend='nc')


# in sample predict
pred = mdl.predict()

#plotting
plt.style.use('bmh')
fig = plt.figure(figsize=(9,7))
ax = plt.gca()
plt.plot(ma1, label='Actual')        
plt.plot(pred, 'r-', label = "In-sample predict")
plt.legend(loc='upper left')

我得到以下内容:

样本内预测似乎是按比例缩放的。那是为什么?

我还绘制了实际和预测的累积总和,因为通常我们会先进行顺序差异来整合数据。

fig = plt.figure(figsize=(9,7))
ax = plt.gca()
plt.plot(ma1.cumsum(), label='Actual')
plt.plot(pred.cumsum(), 'r-', label='Predict')
plt.legend(loc='upper left')

我有这样的事情:

enter image description here

我做错了什么吗?为什么规模如此偏离?

1 个答案:

答案 0 :(得分:0)

这不是一个有意义的情节或练习。

您正在累积一个先行预测,所有这些预测都是从该观察的历史记录或该时间点开始的不同级别开始的。

可以估计具有第一差异的模型并将其预测为ARIMA(0,1,1)。在这种情况下,水平的预测,“typ =”水平“),是基于在前一时间点观察到的预测变化。