簡體   English   中英

使用 python 在 arima 中進行預測

[英]forecasting in arima using python

我像這樣創建了一個 ARIMA model

for i in range(len(testy)):
    model = ARIMA(endog=trainy,exog=trainx,order=(1,0,1))
    model_fit = model.fit()
    ll=testx[i]
    yhat = model_fit.forecast(exog=ll)
    pred.append(yhat[0])
    actual = testy[i]
    all_values.append(actual)
    #print('=%f\t=%f' % (yhat[0], actual))
    print('predicted=%f, expected=%f' % (yhat[0], actual))

現在我希望預測未來 12 周的未來價值。 是否可以?

# Forecast
start_index = len(df.values)
end_index = start_index + 6
forecast = model_fit.predict(start=start_index, end=end_index)
print(forecast)

當我使用上面的代碼片段時,出現如下所示的錯誤。

 ValueError: You must provide exog for ARMAX

編輯:使用的庫是:

import numpy as np
import pandas as pd
import datetime
from matplotlib import pyplot as plt
from numpy import log
from statsmodels.tsa.seasonal import seasonal_decompose
from statsmodels.tsa.stattools import adfuller
from scipy.stats import boxcox
from pandas.plotting import autocorrelation_plot
#from statsmodels.tsa.arima.model import ARIMA
from statsmodels.tsa.arima_model import ARIMA
from statsmodels.tsa.stattools import acf, pacf

事實上,方法 predict 沒有關鍵字參數n_periods使用startendARIMA.predict的幫助你可以找到 arguments 的描述:

start : int, str, or datetime
    Zero-indexed observation number at which to start forecasting, ie.,
    the first forecast is start. Can also be a date string to
    parse or a datetime type.
end : int, str, or datetime
    Zero-indexed observation number at which to end forecasting, ie.,
    the first forecast is start. Can also be a date string to
    parse or a datetime type. However, if the dates index does not
    have a fixed frequency, end must be an integer index if you
    want out of sample prediction

是一個很好的例子,說明如何進行多步預測。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM