[MATLAB Issue 68] Multi-step prediction of multi-variable time series data based on MATLAB's LSTM long short-term memory network including prediction of the future (not single-step prediction)

[MATLAB Issue 68] Multi-step prediction of multi-variable time series data based on MATLAB's LSTM long short-term memory network including prediction of the future (not single-step prediction)

25 times before input and 5 times after output

1. Data conversion

1. Original data

5 columns of time series data, 70 rows of samples,
70×5 data matrix structure
Insert image description here

2. Data conversion

Divide the total data into 14 cells, and
each row represents 5 days of data for 5 variables among the 14 rows of data .
Multi-step prediction: predict the next 5 days of data based on the first 25 days of data,
that is, 5 1cell predicts 1 1cell

For example: cells in rows 1~5 predict the 6th row (1-25 days, predict 26-30 days)
cells in rows 2~6 predict the 7th row (6-30 days, predict 31-35 days)
······
Rows 9-13 cells predict row 14 (41-65 days, forecast 66-70 days)

Secondly, change data_y to 5 25, which is consistent with the length of the data_x sequence
data_add(n,1) ={zeros(5,20)};, add zero value,
that is, convert data_y from 5 5 to 5*25

2. Parameter settings

%% LSTM网络训练
inputsize =5;
outputsize =5;
layers=[sequenceInputLayer(inputsize);
        bilstmLayer(200);
        dropoutLayer(0.2);
        fullyConnectedLayer(outputsize);
        regressionLayer();
        ];
    
 opts = trainingOptions('adam', ...
    'MaxEpochs',2000, ...
    'GradientThreshold',1,...
    'ExecutionEnvironment','cpu',...
    'InitialLearnRate',0.005, ...
    'LearnRateSchedule','piecewise', ...
    'LearnRateDropPeriod',125, ...   %2个epoch后学习率更新
    'LearnRateDropFactor',0.2, ...
    'Shuffle','once',...  % 时间序列长度
    'L2Regularization',0.005,...%正则项系数初始值。建议一开始将正则项系数λ设置为0,先确定一个比较好的learning rate。然后固定该learning rate,给λ一个值(比如1.0),然后根据validation accuracy,将λ增大或者减小10倍(增减10倍是粗调节,当你确定了λ的合适的数量级后,比如λ = 0.01,再进一步地细调节,比如调节为0.020.030.009之类。
    'SequenceLength',25,...
    'MiniBatchSize',10,...%比如mini-batch size设为100,则权重更新的规则为:%也就是将100个样本的梯度求均值,替代online learning方法中单个样本的梯度值
    'Verbose',1,...
'Plots','training-progress');

3. Forecast

1. Test set effect

Enter the last row of data in data_x, that is, 41-65 days,
and output [1-20 constructed data] + 66-70 days of data,
5 days of data after filtering.
Insert image description here
Insert image description here

2. Predict the future

Insert image description here

If you need to predict P1 (71-75) in the next 5 days, you only need to enter
the 5 variable data from days 46-70
and you will get [1*20 constructed data] + data from days 71-75

If you need to predict P2 (76-80) in the next 10 days, you only need to enter
the 5 variable data from days 51 to 75 (data from days 71 to 75 is provided by P1) and
you will get [1*20 constructed data] + day 76- 80 days of data

If you need to predict P3 (81-85) in the next 15 days, you only need to enter
the 5 variable data of days 56-80 (the data of days 76-80 is provided by P2) and
you will get [1*20 constructed data] + the 81st- 85 days of data

4. Code acquisition

Reply "Issue 68" to the private message in the background to get the download link.

Guess you like

Origin blog.csdn.net/qq_29736627/article/details/132175880