我正在建立一个ARIMA模型进行飞行预测。我有10年的数据,我想预测历史飞行。我已经制作了一个ARIMA模型,但始终收到错误消息:“要求endog必须具有ndim 1但必须具有ndim 2”。
这里是代码:
df = read_excel('dataset.xlsx')
df = df[['Year', 'Historical Flights','Country GDP']]
print(df.head())
X = df.iloc[:, :].values
size = int(len(X) * 0.66)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()
for t in range(len(test)):
model = ARIMA(history, order=(2,1,2))
model_fit = model.fit(disp=0)
output = model_fit.forecast()
yhat = output[0]
predictions.append(yhat)
obs = test[t]
history.append(obs)
print('predicted=%f, expected=%f' % (yhat, obs))
error = mean_squared_error(test, predictions)
print('Test MSE: %.3f' % error)
尝试将您对Arima的输入重塑为
model = ARIMA(history.values.reshape(-1).tolist(), order=(2,1,2))
这会将数组的尺寸更改为1D