[英]statsmodel ARMA in sample prediction
I'm using statsmodel ARMA()
to estimate a simulated MA(1)
process: 我正在使用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')
I get the following: 我得到以下内容:
The in-sample prediction seems to be scaled. 样本内预测似乎已缩放。 Why is that?
这是为什么?
I also plotted the cumulative sum of the actual and the predicts, given that usually we do first order difference to integrate the data. 考虑到通常我们对数据进行一阶差分,因此我还绘制了实际值和预测值的累加和。
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')
I got something like this: 我得到这样的东西:
Did I do anything wrong? 我做错了吗? Why is the scale so off?
为什么秤这么小?
That's not really a meaningful plot or exercise. 那不是真正有意义的情节或练习。
You are accumulating one step-ahead forecasts that all start at different levels given by the history for that observation or at that time point. 您正在累积一个逐步的预测,这些预测均始于该观察的历史记录或该时间点的不同级别。
A model with first difference can be estimated and prediction as ARIMA(0,1,1). 可以估计具有第一差异的模型并将其预测为ARIMA(0,1,1)。 In that case the prediction of the level, `typ="level"), is based on the predicted changes added to the observation at the previous time point.
在那种情况下,水平的预测“ typ =“ level”)是基于在前一个时间点添加到观测值的预测变化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.