[英]How forecast values using ARIMAX model in Python?
我試圖在訓練樣本(內生和外生變量)上擬合 ARIMAX 模型,然后使用外生變量(它們可用)進行預測。 我在 Python 中使用statsmodels
模塊。
我有以下代碼:
#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']])
不幸的是,它似乎使用訓練數據集而不是測試數據集來預測樣本內擬合,因為有 100 個預測點。
如果模型中有 2 個滯后,那么我應該從訓練數據集中附加y
的最后 2 個點還是不應該( results
以某種方式保留了有關y
的最后一個值的信息)?
我已經發現了類似的問題,但是,它們與 R 有關。
使用forecast
方法:
results.forecast(steps=5, exog=df_test[['pc1', 'pc2']])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.