简体   繁体   English

如何在 Python 中使用 ARIMAX 模型预测值?

[英]How forecast values using ARIMAX model in Python?

I am trying to fit ARIMAX model on train sample (endogenous and exogenous variables) and then forecast using exogenous variables (they are available).我试图在训练样本(内生和外生变量)上拟合 ARIMAX 模型,然后使用外生变量(它们可用)进行预测。 I am using statsmodels module in Python.我在 Python 中使用statsmodels模块。

I have the following code:我有以下代码:

#split datasets
df_train = df.iloc[:100]
df_test= df.iloc[100:104]

# Define the model
model = ARIMA(endog= df_train['y'], exog=df_train[['x1', 'x2']], order=(2,0,2))
# Fit the model
results = model.fit()

#predict for the next 5 periods
results.predict(steps = 5,  exog = df_test[['pc1', 'pc2']])

Unfortunately, seems it predicts in-sample fit using train dataset but not test dataset, because there are 100 prediction points.不幸的是,它似乎使用训练数据集而不是测试数据集来预测样本内拟合,因为有 100 个预测点。

If there is 2 lags in the model, so should I append last 2 points of y from train dataset or should not ( results somehow preserves information about last value of y )?如果模型中有 2 个滞后,那么我应该从训练数据集中附加y的最后 2 个点还是不应该( results以某种方式保留了有关y的最后一个值的信息)?

Similar question I already found, however, they were related to R.我已经发现了类似的问题,但是,它们与 R 有关。

Use the forecast method:使用forecast方法:

results.forecast(steps=5,  exog=df_test[['pc1', 'pc2']])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM