Time series prediction | MATLAB implements CNN-BiGRU-Attention time series prediction

Time series prediction | MATLAB implements CNN-BiGRU-Attention time series prediction

predictive effect

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

insert image description here

insert image description here
insert image description here

basic introduction

MATLAB implements CNN-BiGRU-Attention time series prediction, and CNN-BiGRU-Attention combines attention mechanism time series prediction.

Model description

Matlab implements CNN-BiGRU-Attention time series prediction
1. data is a data set, the format is excel, univariate time series prediction; 2.
CNN_BiGRU_AttentionTS.m is the main program file, just run it;
3. The command window outputs R2, MAE, MAPE, MSE and MBE;
Note that the program and data are placed in one folder, and the operating environment is Matlab2021b and above.

Note that the program and data are placed in a folder, and the operating environment is Matlab2021b and above.
4. Attention mechanism module:
SEBlock (Squeeze-and-Excitation Block) is a new structural unit that focuses on the channel dimension and adds a channel attention mechanism to the model. This mechanism adds the importance of each feature channel The degree of weight is used to enhance or suppress the corresponding channels for different tasks, so as to extract useful features. The internal operation process of this module is shown in the figure, which is generally divided into three steps: first, the Squeeze compression operation compresses the features of the spatial dimension and keeps the number of feature channels unchanged. Fusing global information is global pooling, and converting each two-dimensional feature channel into a real number. The real number calculation formula is shown in the formula. The real number is obtained by dividing the sum of features obtained by k channels by the value of the spatial dimension, and the spatial dimension is H*W. The second is the Excitation incentive operation, which consists of two fully connected layers and a Sigmoid function. As shown in the formula, s is the output of the incentive operation, σ is the activation function sigmoid, W2 and W1 are the corresponding parameters of the two fully connected layers, and δ is the activation function ReLU, which first reduces the dimensionality of the features and then increases them. The last is the Reweight operation, which weights the previous input features channel by channel to complete the redistribution of the original features on each channel.

1
2

programming

  • Complete program and data acquisition method 1: program exchange of equal value;
  • Complete program and data acquisition method 2: private letter bloggers reply to MATLAB to achieve CNN-BiGRU-Attention time series prediction acquisition.
 
        gruLayer(32,'OutputMode',"last",'Name','bil4','RecurrentWeightsInitializer','He','InputWeightsInitializer','He')
        dropoutLayer(0.25,'Name','drop2')
        % 全连接层
        fullyConnectedLayer(numResponses,'Name','fc')
        regressionLayer('Name','output')    ];

    layers = layerGraph(layers);
    layers = connectLayers(layers,'fold/miniBatchSize','unfold/miniBatchSize');
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 训练选项
if gpuDeviceCount>0
    mydevice = 'gpu';
else
    mydevice = 'cpu';
end
    options = trainingOptions('adam', ...
        'MaxEpochs',MaxEpochs, ...
        'MiniBatchSize',MiniBatchSize, ...
        'GradientThreshold',1, ...
        'InitialLearnRate',learningrate, ...
        'LearnRateSchedule','piecewise', ...
        'LearnRateDropPeriod',56, ...
        'LearnRateDropFactor',0.25, ...
        'L2Regularization',1e-3,...
        'GradientDecayFactor',0.95,...
        'Verbose',false, ...
        'Shuffle',"every-epoch",...
        'ExecutionEnvironment',mydevice,...
        'Plots','training-progress');
%% 模型训练
rng(0);
net = trainNetwork(XrTrain,YrTrain,layers,options);
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
%% 测试数据预测
% 测试集预测
YPred = predict(net,XrTest,"ExecutionEnvironment",mydevice,"MiniBatchSize",numFeatures);
YPred = YPred';
% 数据反归一化
YPred = sig.*YPred + mu;
YTest = sig.*YTest + mu;
————————————————
版权声明:本文为CSDN博主「机器学习之心」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

References

[1] http://t.csdn.cn/pCWSp
[2] https://download.csdn.net/download/kjm13182345320/87568090?spm=1001.2014.3001.5501
[3] https://blog.csdn.net/kjm13182345320/article/details/129433463?spm=1001.2014.3001.5501

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/132222275