为什么将SARIMAX预测转移到训练集中?

2024-05-28 18:11:23 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用SARIMAX预测每日用电量。然而,在我看来,预测的序列发生了变化。有人知道这是怎么发生的吗

total_normalized
            Consumption  Temperature   Radiation  weekly first difference
DATUM                                                                    
2018-01-08     7532.644     1.073611  303.800000                 1666.145
2018-01-09     7643.685     2.169633  189.000000                  848.669
2018-01-10     7471.557     6.381944  113.800000                  470.387
2018-01-11     7419.188     5.160139  190.866667                  522.394
2018-01-12     7441.262     4.401250   95.800000                  637.488

我已将我的数据集拆分为:

train=total_normalized.iloc[:len(total_normalized)-30]

test=total_normalized.iloc[len(total_normalized)-30:]

从这里创建了内生变量和外生变量的序列/数组

endog_train_diff=train['weekly first difference']

endog_test_diff=test['weekly first difference']
exog_train=train[['Temperature','Radiation']].to_numpy()

exog_test=test[['Temperature','Radiation']].to_numpy()

然而,虽然列车组的最后一个指数为2020-08-01,测试组的第一个指数为2020-08-02,但第一个预测消耗量为2020-07-31。我在调试时注意到了这一点

model=sm.tsa.statespace.SARIMAX(endog_train_diff,exog=exog_train,order=(1,1,5),seasonal_order=(0,1,1,7),
trend='ct',enforce_stationarity=False,enforce_invertibility=False)

results=model.fit(disp=False)

forecast = results.forecast(steps=30,exog=exog_test)


Image of the shifted forecast wrt to the original values 这样,测试集的外部值就无法与正确的日期匹配。 我假设,这也会对预测性能产生影响

这是一个已知的问题,还是我的代码中遗漏了什么


Tags: testfalsedifftrain序列totalfirsttemperature

热门问题