带外回归的statsmodel ARIMA动态预测

时间:2019-01-15 16:29:12

标签: python dynamic statsmodels arima

我正在尝试使用多变量Arima来预测price列。我正在[train_start_index:train_end_index]上训练Arima模型,后来又使用它的参数来预测新数据。

while (train_end_index < inputNumber - 1):
        train_end_index = train_start_index + trainLength
        test_start_index = train_end_index
        test_end_index= test_start_index + horizon
        if (filteredData[test_start_index:test_end_index]["day"].values[-1] > 300) and (filteredData[test_start_index:test_end_index]["year"].values[-1] == 2017):
            return predictions, prices
        trainFeatures = filteredData[train_start_index:train_end_index]["totaltx"]
        trainOutput = filteredData[train_start_index:train_end_index]["price"]

        training_arima = sm.tsa.statespace.SARIMAX(endog=trainOutput, exog=trainFeatures, order=(window, 1, 1), trend="ct", initialization='approximate_diffuse')
        training_arima_fit = training_arima.fit(disp=0)

        testFeatures = filteredData[train_start_index:test_end_index]["totaltx"]
        testOutput = filteredData[train_start_index:test_end_index]["price"]

        test_arima = sm.tsa.statespace.SARIMAX(endog=testOutput, exog=testFeatures, order=(window, 1, 1), trend="ct", initialization='approximate_diffuse')
        #res = test_arima.filter(training_arima_fit.params)
        res=test_arima.smooth(training_arima_fit.params)

        predicted = res.predict()[-1:]
        price = filteredData[test_start_index:test_end_index]["price"].values[-1:]

        predictions = np.append(predictions, predicted.values)
        prices = np.append(prices, price)

但是,我在这里遇到问题。为了预测Price(t+horizon),我假设我没有TotalTx(t),...,TotalTx(t+horizon)的值。我只想通过先前训练过的Arima来预测Price(t + horizo​​n)。但是,arima需要TotalTx(t),...,TotalTx(t+horizon)的外生变量。

是否可以建议我使用带有外源回归器的python Arima模型来解决此问题?

谢谢。

0 个答案:

没有答案