本次运行测试环境MATLAB2020b,MATLAB实CNN-LSTM(卷积长短期记忆神经网络)时间序列预测。
卷积神经网络 (CNN) 提取特征,双向长短期记忆 (Bi-LSTM) 保留关键特征以提高预测的准确性。
clc;
clear;
clearvars
% 时间滞后阶数;
Lag = 1:8;
% 训练集比例
ratio = 0.9;
% 批处理样本
MiniBatchSize =24;
% 最大迭代次数
MaxEpochs = 60;
% 学习率
learningrate = 0.005;
%% 加载数据
load data;
%% 在训练和测试中划分顺序
% 在训练和测试中拆分数据。
% 90%的数据用于训练,而10%的数据用于测试。
numStepsTraining = round(ratio*numel(data));
indexTrain = 1:numStepsTraining;
dataTrain = data(indexTrain );
indexTest = numStepsTraining+1:size(data,2);
dataTest = data(indexTest);
inputSize = [1250 12 1];
numHiddenUnits = 10;
layers = [ ...
sequenceInputLayer(inputSize,'Name','input','normalization','none')
sequenceFoldingLayer('Name','fold')
convolution2dLayer([21 1],16,'Name','conv1','Padding','same')
maxPooling2dLayer([7 1],'Stride',7,'Name','maxpool1','Padding','same')
convolution2dLayer([17 1],32,'Name','conv2','Padding','same')
maxPooling2dLayer([6 1],'Stride',6,'Name','maxpool2','Padding','same')
convolution2dLayer([13 1],64,'Name','conv3','Padding','same')
maxPooling2dLayer([7 1],'Stride',7,'Name','maxpool3','Padding','same')
sequenceUnfoldingLayer('Name','unfold')
flattenLayer('Name','flatten')
bilstmLayer(numHiddenUnits,'OutputMode','last','Name','bilstm1')
fullyConnectedLayer(numClasses, 'Name','fc')];
[1] https://download.csdn.net/download/kjm13182345320/86850774?spm=1001.2014.3001.5503
[2] https://download.csdn.net/download/kjm13182345320/86830096?spm=1001.2014.3001.5503
[3] https://download.csdn.net/download/kjm13182345320/86813257?spm=1001.2014.3001.5503