我目前正在使用神经网络,我还是初学者。我的目的是使用MLP来预测流量时间序列(我知道,NARX网络可能更适合时间序列预测,但要求是MLP)。
例如,我想预测当前和历史流Q(t+x)
和降水Q(t...t-n)
等的流量P(t...t-m)
。
我的网络培训(网络的培训,验证和测试)和额外的验证期的结果显示了相对较好的质量(相关性和RMSE)。但是,当我仔细观察训练和验证期的输出时,各个周期的目标存在滞后。我的问题是我不知道为什么。
滞后与我的预测期x完全对应,无论x有多大。
我使用Matlab工具箱中的标准MLP和默认设置(随机分割,trainlm等),比如使用图形NN工具(但我也用我自己的代码测试了其他设置)。
使用简单的Q(t)
NAR-net就是同样的问题。如果我使用常规数据(例如使用sin(t+x)
预测sin(t..t-n)
或使用矩形函数进行预测,则没有时间偏移,这一切都很好。
只有当我使用真实世界数据或不规则(但最常量)的数据时,例如[0.12 0.14 0.13 0.1 0.1 0.1 ...
(n次)0.1 ... 0.1 0.1 0.14 0.15 0.12 ...]
,目标和输出之间才会发生转换。虽然我使用目标Q(t+x)
训练网络,但实际训练输出为Q(t)
。我还尝试了一些其他输入变量组合,从少到多的信息。我的时间序列是7年以上,每小时分辨率。但它也会出现在其他决议中。
我的工作中是否存在错误或我可以尝试的事情。我读过其他一些人也有这个问题,但没有解决方案?我认为这不是我的实现失败,因为我也尝试了matlab工具和窦功能,并且有相同的结果。如果我忽略了这种转变,那么值的准确性也不错(这就是为什么相关性和rmse的优点明显也很好)。
我使用matlab 2012。
这里也是一个简约的代码示例,只有最重要的导入点。但也很好地说明了问题。
%% minimalstic example
% but there is the same problem with more input variables
load Q
%% create net inputs and targets
% start point of t
t = 100;
% history data of Q -> Q(t-1), Q(t-2), Q(t-3)
inputs = [Q(t-1:end-1,1) Q(t-2:end-2,1) Q(t-3:end-3,1)]';
% timestep t that want to be predicted
targets = Q(t:end,1)';
%% create fitting net (MLP)
% but it is the same problem for NARnet
% and from here, you can also use the NN graphical tool
% number of hidden neurons
numHiddenNeurons = 6; % the described problem is not dependent on this
% point, therefor it is freely chosen
net = fitnet(numHiddenNeurons); % same problem if choosing the old version newfit
% default MLP settings, no changes, but the problem even exist with other
% combinations of settings
% train net
[trained_net,tr] = train(net,inputs,targets);
% apply trained net with given data (create net outputs)
outputs = sim(trained_net,inputs);
figure(1)
hold on
bar(targets',0.6,'FaceColor','r','EdgeColor','none')
bar(outputs',0.2,'FaceColor','b','EdgeColor','none')
legend('observation','prediction')
% please zoom very far to see single bars!! the bar plot shows very good
% the time shift
% if you choose a bigger forecasting time, the shift will also be better to
% see
%% the result: targets(1,1)=Q(t), outputs(1,1)=Q(t-1)
%% now try the sinus function, the problem will not be there
x = 1:1:1152;
SIN = sin(x);
inputs = [SIN(1,t-1:end-1);SIN(1,t-2:end-2);SIN(1,t-3:end-3)];
targets = SIN(1,t:end);
% start again from above, creating the net
我没有足够的声誉来上传两个代码结果的摘录,提前一步预测。
答案 0 :(得分:1)
考虑使用前一时期的最近变化作为输入,考虑不是流量的绝对值,而是预测来自前一时期的流量的更改。正如上面的Diphtong所指出的,很可能是先前的流量值不能预测(包含没有关于下一个流量值的有用信息)。
从概念上讲,这类似于预测random walk的下一个值。想象一下,您遇到的情况是函数的下一个值等于当前值加上-1.0和+1.0之间的一些随机数。如果您尝试预测前一个值的下一个值,那么任何函数近似/回归函数可以做的最小化预测误差的最佳方法是使用当前值作为下一个值的最佳预测值。
但是,在您的情况下,以前的流值中仍然可能存在某些信息。为防止当前值超过错误项,请拒绝网络使用当前值作为预测器,方法是将绝对流量值的导数输入。如果这些信息中没有任何有用的信息,它应该通过始终预测0来最小化错误。
总之,请尝试:
答案 1 :(得分:0)
这个"时移"你观察的正是@Diphtong所提到的:你的神经网络无法解决输入和输出之间的关系,所以它就像一个天真的预测器" (查阅)在(在金融股票市场的世界里)明天股票价格的最佳预测是今天的价格。
这可能会有所帮助,但我已经看到输入时间序列的增量,LOG()和SQRT()执行相同的...