[MATLAB Issue 65] Introduction to future ideas for predicting the future of multi-input single-output data based on LSTM long short-term memory network (short-term prediction)

[MATLAB Issue 65] Introduction to future ideas for predicting the future of multi-input single-output data based on LSTM long short-term memory network (short-term prediction)

Multi-input and single-output sliding window regression prediction has been realized in the 13th issue of the previous period.
Multi-input and single-output sliding window regression prediction
has been realized in the 54th period of the previous period. Multi-input
and multi-output sliding window regression prediction has been realized.

1. Realization effect

This time, we realize the idea of ​​predicting the future using multi-input and single-output data, aiming at short-term prediction.

1. Training process
:Insert image description here

2. Test set fitting effect:
Insert image description here
“RMSE2” “1.4041”
“MAPE2” “0.059405”

3.
Predict future effects:

Insert image description here

2. Data construction and processing:

Construction principle: sliding window number = predicted future number

Original data:
198 rows (representing 198 days), 21 columns of data, of which the first 20 columns are variables and the 21st column is the dependent variable.
If you predict future dependent variables, you need to construct input data at the current moment and output data at the future moment.
Assuming that 18 data in the future are predicted, the first sample can be:
input X1-X20 data of day1-18 (data matrix: 18×20), output Y19-Y36 (18×1) of day19-36, and the
last sample is :
Input the X1-X20 data of day163-180 (data matrix: 18×20), and output the Y181-Y198 of day181-198 (18×1)

The first 90% data training (146), the last 10% data testing (17)
prediction set input data is:
input X1-X20 data of day181-198 (data matrix: 18×20), output Y199- of day199-216 Y216 (18×1)

3. LSTM parameter settings

inputSize = size(input,1);   %数据输入x的特征维度
outputSize = k;  %数据输出y的特征维度  
numhidden_units1=100;
numhidden_units2=100;
% lstm
layers = [ ...
    sequenceInputLayer(inputSize,'name','input')                             %输入层设置
   % lstmLayer(numhidden_units1,'Outputmode','sequence')                     %学习层设置(cell层)
    lstmLayer(numhidden_units1,'Outputmode','sequence','name','hidden1')     %隐藏层1
    dropoutLayer(0.3,'name','dropout_1')                                     %隐藏层1权重丢失率,防止过拟合
    lstmLayer(numhidden_units2,'Outputmode','last','name','hidden2')         %隐藏层2
     dropoutLayer(0.3,'name','dropout_2')                                    %隐藏层2权重丢失率,防止过拟合
    fullyConnectedLayer(outputSize,'name','fullconnect')                     %全连接层设置(outputsize:预测值的特征维度)
    regressionLayer('name','out')];                                          %回归层(因为负荷预测值为连续值,所以为回归层) 

% trainoption
opts = trainingOptions('adam', ...        %优化算法
    'MaxEpochs',50, ...                   %遍历样本最大循环数
    'GradientThreshold',1,...             %梯度阈值
    'ExecutionEnvironment','cpu',...      %运算环境
    'InitialLearnRate',0.001, ...         %初始学习率
    'LearnRateSchedule','piecewise', ...  % 学习率计划
    'LearnRateDropPeriod',2, ...          %2个epoch后学习率更新
    'LearnRateDropFactor',0.9, ...        %学习率衰减速度
    'MiniBatchSize',1,...             % 批处理样本大小
    'Verbose',0, ...                      %命令控制台是否打印训练过程
    'Plots','training-progress'...        % 打印训练进度
    );

4. Code acquisition

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

Guess you like

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