SARIMA 具有多种特征,在样本中领先 n 步

问题描述 投票:0回答:1

我的 SARIMA 有问题。我想创建一个模型,根据多个特征预测前一天的值。我使用了以下代码,但我不知道如何合并所有其他功能(代码中的“数据”):

data = allmerged[['lagged_actual_total_load_MW', 'DA_total_load_MW', 'DA_onshore_wind_MW', 'DA_offshore_wind_MW', 'DA_solar_MW', 'lagged_actual_wind_offshore_MW', 'lagged_actual_wind_onshore_MW', 'lagged_actual_solar_MW', 'DA_price']]
    y = allmerged['imbalance_MW']

size = int(len(allmerged) - 96)
train, test = allmerged['imbalance_MW'][0:size], allmerged['imbalance_MW'][size:len(allmerged)]

print('\t SARIMA MODEL : In - Sample Forecasting \n')

history = [x for x in train]
predictions = []

for t in range(len(test)):
    
    model = sm.tsa.statespace.SARIMAX(history,order = (1,0,1),seasonal_order = (1,1,1,4))
    model_fit = model.fit(disp = 0)
    
    output = model_fit.forecast()
    
    yhat = output[0]
    predictions.append(float(yhat))
    
    obs = test[t]
    history.append(obs)
    
    print('predicted = %f, expected = %f' % (np.exp(yhat), np.exp(obs)))

predictions_series = pd.Series(predictions, index = test.index)
fig,ax = plt.subplots(nrows = 1,ncols = 1,figsize = (15,5))

plt.subplot(1,1,1)
plt.plot(allmerged['imbalance_MW'],label = 'Expected Values')
plt.plot(np.exp(predictions_series),label = 'Predicted Values');
plt.legend(loc="upper left")
plt.show()
prediction feature-selection arima forecast sarimax
1个回答
0
投票

您可以通过

exog
参数传递附加数据(外生数据):

model = sm.tsa.statespace.SARIMAX(endog=history, exog=<your_exogenous_data>, order=(1, 0, 1), seasonal_order=(1, 1, 1, 4)) 

外生数据可以是 DataFrame 或 Series。请记住,在进行预测时必须提供外生数据:

predictions = model_fit.forecast(endog=predictions, exog=<your_exogenous_data>, index = test.index)

https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.sarimax.SARIMAX.html

© www.soinside.com 2019 - 2024. All rights reserved.