<pre><code>y_hat=model_fit.predict(len(data),len(data))
</code></pre>
<p>你的开始值是len(data),结束值也是一样的,所以它给你一个预测值。你知道吗</p>
<p>我在我的项目中使用了forecast()。下面是我的代码片段:</p>
<pre><code>from statsmodels.tsa.stattools import acf
# Create Training and Test
train = df[:3000]
test = df[3000:]
# Build Model
# model = ARIMA(train, order=(3,2,1))
model = ARIMA(train, order=(1, 1, 1))
fitted = model.fit(disp=-1)
# Forecast
fc, se, conf = fitted.forecast(len(test), alpha=0.05) # 95% conf
# Make as pandas series
fc_series = pd.Series(fc, index=test.index)
lower_series = pd.Series(conf[:, 0], index=test.index)
upper_series = pd.Series(conf[:, 1], index=test.index)
# Plot
plt.figure(figsize=(12,5), dpi=100)
plt.plot(train, label='training')
plt.plot(test, label='actual')
plt.plot(fc_series, label='forecast')
plt.fill_between(lower_series.index, lower_series, upper_series,
color='k', alpha=.15)
plt.title('Forecast vs Actuals')
plt.legend(loc='upper left', fontsize=8)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/ozxGG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ozxGG.png" alt="enter image description here"/></a></p>
<p>预测值在我的图表中是恒定的,因为我的数据有季节性成分。你知道吗</p>